Skip to content

Commit 68fed47

Browse files
committed
fix: resolve possibly-null playbackJob in recordings:play
The deferred .finally() callback captured the mutable `playbackJob` let, so TypeScript could not carry the post-guard non-null narrowing into the closure (TS18047). Capture the job into a const after the null check and reference that, clearing the two errors and making the electron project typecheck cleanly.
1 parent 9e20c9a commit 68fed47

1 file changed

Lines changed: 11 additions & 8 deletions

File tree

electron/ipc/handlers.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -462,24 +462,27 @@ export function registerHandlers(fixtures: TestFixtures | null = null): void {
462462
throw lastError instanceof Error ? lastError : new Error('Failed to download recording clip');
463463
}
464464

465-
activeRecordingPlaybackJobs.set(cameraId, playbackJob);
466-
if (playbackJob.assetPath) {
467-
streamManager.registerActivePlaybackAsset(playbackJob.assetPath, playbackJob.completed);
465+
// Capture into a const so the non-null narrowing survives into the
466+
// deferred .finally() closure below (playbackJob is a mutable let).
467+
const job = playbackJob;
468+
activeRecordingPlaybackJobs.set(cameraId, job);
469+
if (job.assetPath) {
470+
streamManager.registerActivePlaybackAsset(job.assetPath, job.completed);
468471
}
469-
void playbackJob.completed
472+
void job.completed
470473
.catch(() => undefined)
471474
.finally(() => {
472-
if (activeRecordingPlaybackJobs.get(cameraId) === playbackJob) {
475+
if (activeRecordingPlaybackJobs.get(cameraId) === job) {
473476
activeRecordingPlaybackJobs.delete(cameraId);
474477
}
475-
if (playbackJob.assetPath) {
476-
streamManager.unregisterActivePlaybackAsset(playbackJob.assetPath);
478+
if (job.assetPath) {
479+
streamManager.unregisterActivePlaybackAsset(job.assetPath);
477480
}
478481
});
479482

480483
const relativeAssetPath = path.relative(
481484
path.join(os.tmpdir(), 'vigilatus-playback'),
482-
playbackJob.assetPath ?? '',
485+
job.assetPath ?? '',
483486
);
484487
const url = streamManager.getPlaybackAssetUrl(relativeAssetPath);
485488
console.info(`[recordings:play:${cameraId}] returning URL=${url}`);

0 commit comments

Comments
 (0)