Skip to content

Commit 58916c0

Browse files
committed
fix: Remove non-null assertion in withTimeout by initializing timeoutId with undefined
1 parent ea09dcd commit 58916c0

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

packages/durabletask-js/src/utils/backoff.util.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ export async function withTimeout<T>(
213213
timeoutMs: number,
214214
timeoutMessage = "Operation timed out",
215215
): Promise<T> {
216-
let timeoutId: ReturnType<typeof setTimeout>;
216+
let timeoutId: ReturnType<typeof setTimeout> | undefined;
217217

218218
const timeoutPromise = new Promise<never>((_, reject) => {
219219
timeoutId = setTimeout(() => reject(new Error(timeoutMessage)), timeoutMs);
@@ -222,6 +222,8 @@ export async function withTimeout<T>(
222222
try {
223223
return await Promise.race([promise, timeoutPromise]);
224224
} finally {
225-
clearTimeout(timeoutId!);
225+
if (timeoutId !== undefined) {
226+
clearTimeout(timeoutId);
227+
}
226228
}
227229
}

0 commit comments

Comments
 (0)