Skip to content

Commit 95e5654

Browse files
authored
chore: use fromPartial instead of suppressing ts-errors (#1949)
Automated code migration to shoehorn's `fromPartial` API.
1 parent b0b2d6e commit 95e5654

File tree

3 files changed

+114
-91
lines changed

3 files changed

+114
-91
lines changed

packages/client/src/devices/__tests__/SpeakerManager.test.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2+
import { fromPartial } from '@total-typescript/shoehorn';
23
import {
34
emitDeviceIds,
45
mockAudioDevices,
@@ -80,11 +81,13 @@ describe('SpeakerManager.test', () => {
8081

8182
it('set participant volume', () => {
8283
const call = manager['call'];
83-
// @ts-expect-error - incomplete data
84-
call.state.updateOrAddParticipant('session-id', {
85-
audioVolume: undefined,
86-
sessionId: 'session-id',
87-
});
84+
call.state.updateOrAddParticipant(
85+
'session-id',
86+
fromPartial({
87+
audioVolume: undefined,
88+
sessionId: 'session-id',
89+
}),
90+
);
8891

8992
manager.setParticipantVolume('session-id', 0.5);
9093
let participant = call.state.findParticipantBySessionId('session-id');

packages/client/src/rtc/__tests__/layers.test.ts

Lines changed: 99 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import './mocks/webrtc.mocks';
22
import { describe, expect, it, vi } from 'vitest';
3+
import { fromPartial } from '@total-typescript/shoehorn';
34
import {
45
AudioBitrateProfile,
56
PublishOption,
@@ -24,13 +25,12 @@ describe('videoLayers', () => {
2425
const targetBitrate = 3000000;
2526
vi.spyOn(track, 'getSettings').mockReturnValue({ width, height });
2627

27-
const publishOption: PublishOption = {
28+
const publishOption: PublishOption = fromPartial({
2829
bitrate: targetBitrate,
29-
// @ts-expect-error - incomplete data
3030
codec: { name: 'vp8' },
3131
videoDimension: { width, height },
3232
fps: 30,
33-
};
33+
});
3434
const layers = computeVideoLayers(track, publishOption);
3535
expect(layers).toEqual([
3636
{
@@ -66,26 +66,29 @@ describe('videoLayers', () => {
6666
it('should return undefined for audio track', () => {
6767
const track = new MediaStreamTrack();
6868
expect(
69-
// @ts-expect-error - incomplete data
70-
computeVideoLayers(track, { trackType: TrackType.AUDIO }),
69+
computeVideoLayers(track, fromPartial({ trackType: TrackType.AUDIO })),
7170
).toBeUndefined();
7271
expect(
73-
// @ts-expect-error - incomplete data
74-
computeVideoLayers(track, { trackType: TrackType.SCREEN_SHARE_AUDIO }),
72+
computeVideoLayers(
73+
track,
74+
fromPartial({ trackType: TrackType.SCREEN_SHARE_AUDIO }),
75+
),
7576
).toBeUndefined();
7677
});
7778

7879
it('should use predefined bitrate values when track dimensions cant be determined', () => {
7980
const bitrate = 3000000;
8081
const track = new MediaStreamTrack();
8182
vi.spyOn(track, 'getSettings').mockReturnValue({});
82-
const layers = computeVideoLayers(track, {
83-
bitrate,
84-
// @ts-expect-error - incomplete data
85-
codec: { name: 'vp8' },
86-
fps: 30,
87-
videoDimension: { width: 320, height: 180 },
88-
});
83+
const layers = computeVideoLayers(
84+
track,
85+
fromPartial({
86+
bitrate,
87+
codec: { name: 'vp8' },
88+
fps: 30,
89+
videoDimension: { width: 320, height: 180 },
90+
}),
91+
);
8992
expect(layers).toEqual([
9093
{
9194
active: true,
@@ -104,13 +107,15 @@ describe('videoLayers', () => {
104107
const width = 320;
105108
const height = 240;
106109
vi.spyOn(track, 'getSettings').mockReturnValue({ width, height });
107-
const layers = computeVideoLayers(track, {
108-
bitrate: 0,
109-
// @ts-expect-error - incomplete data
110-
codec: { name: 'vp8' },
111-
fps: 30,
112-
videoDimension: { width, height },
113-
});
110+
const layers = computeVideoLayers(
111+
track,
112+
fromPartial({
113+
bitrate: 0,
114+
codec: { name: 'vp8' },
115+
fps: 30,
116+
videoDimension: { width, height },
117+
}),
118+
);
114119
expect(layers.length).toBe(1);
115120
const [q] = layers;
116121
expect(q.rid).toBe('q');
@@ -123,13 +128,15 @@ describe('videoLayers', () => {
123128
const width = 640;
124129
const height = 480;
125130
vi.spyOn(track, 'getSettings').mockReturnValue({ width, height });
126-
const layers = computeVideoLayers(track, {
127-
bitrate: 0,
128-
// @ts-expect-error - incomplete data
129-
codec: { name: 'vp8' },
130-
fps: 30,
131-
videoDimension: { width, height },
132-
});
131+
const layers = computeVideoLayers(
132+
track,
133+
fromPartial({
134+
bitrate: 0,
135+
codec: { name: 'vp8' },
136+
fps: 30,
137+
videoDimension: { width, height },
138+
}),
139+
);
133140
expect(layers.length).toBe(2);
134141
const [q, h] = layers;
135142
expect(q.rid).toBe('q');
@@ -145,13 +152,15 @@ describe('videoLayers', () => {
145152
const width = 1280;
146153
const height = 720;
147154
vi.spyOn(track, 'getSettings').mockReturnValue({ width, height });
148-
const layers = computeVideoLayers(track, {
149-
bitrate: 0,
150-
// @ts-expect-error - incomplete data
151-
codec: { name: 'vp8' },
152-
fps: 30,
153-
videoDimension: { width, height },
154-
});
155+
const layers = computeVideoLayers(
156+
track,
157+
fromPartial({
158+
bitrate: 0,
159+
codec: { name: 'vp8' },
160+
fps: 30,
161+
videoDimension: { width, height },
162+
}),
163+
);
155164
expect(layers.length).toBe(3);
156165
const [q, h, f] = layers;
157166
expect(q.rid).toBe('q');
@@ -171,13 +180,15 @@ describe('videoLayers', () => {
171180
width: 1280,
172181
height: 720,
173182
});
174-
const layers = computeVideoLayers(track, {
175-
maxTemporalLayers: 3,
176-
maxSpatialLayers: 3,
177-
// @ts-expect-error - incomplete data
178-
codec: { name: 'vp9' },
179-
videoDimension: { width: 1280, height: 720 },
180-
});
183+
const layers = computeVideoLayers(
184+
track,
185+
fromPartial({
186+
maxTemporalLayers: 3,
187+
maxSpatialLayers: 3,
188+
codec: { name: 'vp9' },
189+
videoDimension: { width: 1280, height: 720 },
190+
}),
191+
);
181192
expect(layers.length).toBe(3);
182193
expect(layers[0].scalabilityMode).toBe('L3T3_KEY');
183194
expect(layers[0].rid).toBe('q');
@@ -187,8 +198,10 @@ describe('videoLayers', () => {
187198

188199
it('should activate only a single layer when useSingleLayer is true', () => {
189200
const track = new MediaStreamTrack();
190-
// @ts-expect-error - incomplete data
191-
const layers = computeVideoLayers(track, { useSingleLayer: true });
201+
const layers = computeVideoLayers(
202+
track,
203+
fromPartial({ useSingleLayer: true }),
204+
);
192205
expect(layers.length).toBe(3);
193206
expect(layers[0].active).toBe(false);
194207
expect(layers[0].rid).toBe('q');
@@ -201,22 +214,26 @@ describe('videoLayers', () => {
201214
it('should activate only a single layer when useSingleLayer is true in single layer mode', () => {
202215
const track = new MediaStreamTrack();
203216
vi.spyOn(track, 'getSettings').mockReturnValue({ width: 320, height: 180 });
204-
// @ts-expect-error - incomplete data
205-
const layers = computeVideoLayers(track, { useSingleLayer: true });
217+
const layers = computeVideoLayers(
218+
track,
219+
fromPartial({ useSingleLayer: true }),
220+
);
206221
expect(layers.length).toBe(1);
207222
expect(layers[0].active).toBe(true);
208223
expect(layers[0].rid).toBe('q');
209224
});
210225

211226
it('should activate only one temporal layer when useSingleLayer is true for SVC', () => {
212227
const track = new MediaStreamTrack();
213-
const layers = computeVideoLayers(track, {
214-
// @ts-expect-error - incomplete data
215-
codec: { name: 'vp9' },
216-
maxSpatialLayers: 3,
217-
maxTemporalLayers: 3,
218-
useSingleLayer: true,
219-
});
228+
const layers = computeVideoLayers(
229+
track,
230+
fromPartial({
231+
codec: { name: 'vp9' },
232+
maxSpatialLayers: 3,
233+
maxTemporalLayers: 3,
234+
useSingleLayer: true,
235+
}),
236+
);
220237
expect(layers.length).toBe(3);
221238
expect(layers[0].rid).toBe('q');
222239
expect(layers[0].active).toBe(false);
@@ -318,13 +335,15 @@ describe('videoLayers', () => {
318335

319336
it('should use integer for maxBitrate', () => {
320337
const track = new MediaStreamTrack();
321-
const layers = computeVideoLayers(track, {
322-
bitrate: 2999777,
323-
// @ts-expect-error - incomplete data
324-
codec: { name: 'vp8' },
325-
videoDimension: { width: 1920, height: 1080 },
326-
fps: 30,
327-
});
338+
const layers = computeVideoLayers(
339+
track,
340+
fromPartial({
341+
bitrate: 2999777,
342+
codec: { name: 'vp8' },
343+
videoDimension: { width: 1920, height: 1080 },
344+
fps: 30,
345+
}),
346+
);
328347
expect(layers).toBeDefined();
329348
for (const layer of layers!) {
330349
expect(Number.isInteger(layer.width)).toBe(true);
@@ -422,40 +441,46 @@ describe('audioLayers', () => {
422441
it('should use predefined bitrates when publish options are missing', () => {
423442
expect(
424443
computeAudioLayers(
425-
// @ts-expect-error - incomplete data
426-
{ trackType: TrackType.AUDIO, id: 1, audioBitrateProfiles: [] },
444+
fromPartial({
445+
trackType: TrackType.AUDIO,
446+
id: 1,
447+
audioBitrateProfiles: [],
448+
}),
427449
{ audioBitrateProfile: AudioBitrateProfile.VOICE_STANDARD_UNSPECIFIED },
428450
),
429451
).toEqual([{ maxBitrate: 64000 }]);
430452
expect(
431453
computeAudioLayers(
432-
// @ts-expect-error - incomplete data
433-
{ trackType: TrackType.AUDIO, id: 1, audioBitrateProfiles: [] },
454+
fromPartial({
455+
trackType: TrackType.AUDIO,
456+
id: 1,
457+
audioBitrateProfiles: [],
458+
}),
434459
{ audioBitrateProfile: AudioBitrateProfile.VOICE_HIGH_QUALITY },
435460
),
436461
).toEqual([{ maxBitrate: 128000 }]);
437462
expect(
438463
computeAudioLayers(
439-
// @ts-expect-error - incomplete data
440-
{ trackType: TrackType.AUDIO, id: 1, audioBitrateProfiles: [] },
464+
fromPartial({
465+
trackType: TrackType.AUDIO,
466+
id: 1,
467+
audioBitrateProfiles: [],
468+
}),
441469
{ audioBitrateProfile: AudioBitrateProfile.MUSIC_HIGH_QUALITY },
442470
),
443471
).toEqual([{ maxBitrate: 128000 }]);
444472
});
445473

446474
it('should use the predefined bitrate when the SFU does not provide audioBitrateProfiles', () => {
447475
expect(
448-
computeAudioLayers(
449-
// @ts-expect-error - incomplete data
450-
{ trackType: TrackType.AUDIO, id: 1 },
451-
{ audioBitrateProfile: AudioBitrateProfile.VOICE_STANDARD_UNSPECIFIED },
452-
),
476+
computeAudioLayers(fromPartial({ trackType: TrackType.AUDIO, id: 1 }), {
477+
audioBitrateProfile: AudioBitrateProfile.VOICE_STANDARD_UNSPECIFIED,
478+
}),
453479
).toEqual([{ maxBitrate: 64000 }]);
454480
});
455481

456482
it('should respect the bitrates provided in publish options', () => {
457-
// @ts-expect-error - incomplete data
458-
const config: PublishOption = {
483+
const config: PublishOption = fromPartial({
459484
trackType: TrackType.AUDIO,
460485
id: 1,
461486
audioBitrateProfiles: [
@@ -472,7 +497,7 @@ describe('audioLayers', () => {
472497
bitrate: 192000,
473498
},
474499
],
475-
};
500+
});
476501
expect(
477502
computeAudioLayers(config, {
478503
audioBitrateProfile: AudioBitrateProfile.VOICE_STANDARD_UNSPECIFIED,

packages/client/src/store/__tests__/CallState.test.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import '../../rtc/__tests__/mocks/webrtc.mocks';
22
import { describe, expect, it, vi } from 'vitest';
33
import { anyNumber } from 'vitest-mock-extended';
4+
import { fromPartial } from '@total-typescript/shoehorn';
45
import { StreamVideoParticipant, VisibilityState } from '../../types';
56
import { CallingState } from '../CallingState';
67
import { CallState } from '../CallState';
@@ -56,8 +57,7 @@ describe('CallState', () => {
5657
it(`shouldn't emit when primitive (backstage) values didn't change`, () => {
5758
const state = new CallState();
5859
const updateWith = (value: boolean) => {
59-
// @ts-expect-error incomplete data
60-
state.updateFromCallResponse({ backstage: value });
60+
state.updateFromCallResponse(fromPartial({ backstage: value }));
6161
};
6262

6363
updateWith(false);
@@ -138,8 +138,7 @@ describe('CallState', () => {
138138
it(`shouldn't emit when string arrays (blockedUserIds) value didn't change`, () => {
139139
const state = new CallState();
140140
const updateWith = (value: string[]) => {
141-
// @ts-expect-error incomplete data
142-
state.updateFromCallResponse({ blocked_user_ids: value });
141+
state.updateFromCallResponse(fromPartial({ blocked_user_ids: value }));
143142
};
144143

145144
updateWith(['a', 'b']);
@@ -640,25 +639,21 @@ describe('CallState', () => {
640639
describe('recording and broadcasting events', () => {
641640
it('handles call.recording_started events', () => {
642641
const state = new CallState();
643-
// @ts-expect-error incomplete data
644-
state.updateFromEvent({ type: 'call.recording_started' });
642+
state.updateFromEvent(fromPartial({ type: 'call.recording_started' }));
645643
expect(state.recording).toBe(true);
646644
});
647645

648646
it('handles call.recording_stopped events', () => {
649647
const state = new CallState();
650-
// @ts-expect-error incomplete data
651-
state.updateFromEvent({ type: 'call.recording_stopped' });
648+
state.updateFromEvent(fromPartial({ type: 'call.recording_stopped' }));
652649
expect(state.recording).toBe(false);
653650
});
654651

655652
it('handles call.recording_failed events', () => {
656653
const state = new CallState();
657-
// @ts-expect-error incomplete data
658-
state.updateFromEvent({ type: 'call.recording_started' });
654+
state.updateFromEvent(fromPartial({ type: 'call.recording_started' }));
659655
expect(state.recording).toBe(true);
660-
// @ts-expect-error incomplete data
661-
state.updateFromEvent({ type: 'call.recording_failed' });
656+
state.updateFromEvent(fromPartial({ type: 'call.recording_failed' }));
662657
expect(state.recording).toBe(false);
663658
});
664659

0 commit comments

Comments
 (0)