diff --git a/async/abortable_test.ts b/async/abortable_test.ts index 7da8e97806af..c9f3b4254b0e 100644 --- a/async/abortable_test.ts +++ b/async/abortable_test.ts @@ -130,7 +130,7 @@ Deno.test("abortable.AsyncIterable() handles already aborted signal", async () = Deno.test("abortable.AsyncIterable() calls return before throwing", async () => { const c = new AbortController(); let returnCalled = false; - let timeoutId: number; + let timeoutId; const iterable: AsyncIterable = { [Symbol.asyncIterator]: () => ({ next: () => diff --git a/async/unstable_abortable_test.ts b/async/unstable_abortable_test.ts index 060209877f33..eae51bd9a6e7 100644 --- a/async/unstable_abortable_test.ts +++ b/async/unstable_abortable_test.ts @@ -130,7 +130,7 @@ Deno.test("abortable.AsyncIterable() handles already aborted signal", async () = Deno.test("abortable.AsyncIterable() calls return before throwing", async () => { const c = new AbortController(); let returnCalled = false; - let timeoutId: number; + let timeoutId; const iterable: AsyncIterable = { [Symbol.asyncIterator]: () => ({ next: () => diff --git a/async/unstable_throttle.ts b/async/unstable_throttle.ts index e68020d925f9..410db695b8bf 100644 --- a/async/unstable_throttle.ts +++ b/async/unstable_throttle.ts @@ -106,7 +106,7 @@ export function throttle>( options?: ThrottleOptions, ): ThrottledFunction { const ensureLast = Boolean(options?.ensureLastCall); - let timeout = -1; + let timeout: ReturnType | undefined; let lastExecution = -Infinity; let flush: (() => void) | null = null; diff --git a/async/unstable_wait_for.ts b/async/unstable_wait_for.ts index 748742426fe9..489cae4a7b4b 100644 --- a/async/unstable_wait_for.ts +++ b/async/unstable_wait_for.ts @@ -51,7 +51,7 @@ export function waitFor( const { step = 100 } = options; // Create a new promise that resolves when the predicate is true - let timer: number; + let timer: ReturnType; const p: Promise = new Promise(function (resolve) { const setTimer = () => { timer = setTimeout(async () => { diff --git a/cache/ttl_cache.ts b/cache/ttl_cache.ts index 7f93795a3642..f0251c1f53ab 100644 --- a/cache/ttl_cache.ts +++ b/cache/ttl_cache.ts @@ -93,7 +93,7 @@ export interface TtlCacheOptions { export class TtlCache extends Map implements MemoizationCache { #defaultTtl: number; - #timeouts = new Map(); + #timeouts = new Map(); #eject?: ((ejectedKey: K, ejectedValue: V) => void) | undefined; #slidingExpiration: boolean; #entryTtls?: Map; diff --git a/cli/unstable_progress_bar.ts b/cli/unstable_progress_bar.ts index 8201561106bd..ea49843a98b6 100644 --- a/cli/unstable_progress_bar.ts +++ b/cli/unstable_progress_bar.ts @@ -193,7 +193,7 @@ export class ProgressBar { max: number; #writer: WritableStreamDefaultWriter; - #id: number; + #id; #startTime: number; #previousTime: number; #previousValue: number; diff --git a/cli/unstable_spinner.ts b/cli/unstable_spinner.ts index 095c6be269c6..6e9bbd498eaf 100644 --- a/cli/unstable_spinner.ts +++ b/cli/unstable_spinner.ts @@ -139,7 +139,7 @@ export class Spinner { #interval: number; #color: Color | undefined; - #intervalId: number | null = null; + #intervalId: ReturnType | null = null; #output: typeof Deno.stdout | typeof Deno.stderr; /** diff --git a/testing/README.md b/testing/README.md index 2ab30a4e93e5..67714980e955 100644 --- a/testing/README.md +++ b/testing/README.md @@ -10,7 +10,7 @@ This package provides utilities for testing. import { assertSpyCalls, spy } from "@std/testing/mock"; import { FakeTime } from "@std/testing/time"; -function secondInterval(cb: () => void): number { +function secondInterval(cb: () => void) { return setInterval(cb, 1000); } diff --git a/testing/bdd_test.ts b/testing/bdd_test.ts index df44d5787a68..e5fa4fae317f 100644 --- a/testing/bdd_test.ts +++ b/testing/bdd_test.ts @@ -42,7 +42,7 @@ interface GlobalContext { } let timerIdx = 1; -const timers = new Map(); +const timers = new Map(); function hookFns() { timerIdx = 1; timers.clear(); diff --git a/testing/mock.ts b/testing/mock.ts index 71f53944e96e..76a2f53ef203 100644 --- a/testing/mock.ts +++ b/testing/mock.ts @@ -293,7 +293,7 @@ * } from "@std/testing/mock"; * import { FakeTime } from "@std/testing/time"; * - * function secondInterval(cb: () => void): number { + * function secondInterval(cb: () => void) { * return setInterval(cb, 1000); * } * diff --git a/testing/time.ts b/testing/time.ts index 7afd02535027..53463e4a3e1a 100644 --- a/testing/time.ts +++ b/testing/time.ts @@ -10,7 +10,7 @@ * } from "@std/testing/mock"; * import { FakeTime } from "@std/testing/time"; * - * function secondInterval(cb: () => void): number { + * function secondInterval(cb: () => void) { * return setInterval(cb, 1000); * } * @@ -138,15 +138,15 @@ function assertIsCallbackFunction( } } -const fakeSetTimeout: typeof globalThis.setTimeout = function ( - callback, +function fakeSetTimeout( + callback: string | ((...args: unknown[]) => unknown), delay = 0, - ...args -) { + ...args: unknown[] +): number { assertIsCallbackFunction(callback, "setTimeout"); if (!time) throw new TimeError("Cannot set timeout: time is not faked"); return setTimer(callback, delay, args, false); -}; +} function fakeClearTimeout(id?: unknown) { if (!time) throw new TimeError("Cannot clear timeout: time is not faked"); @@ -155,15 +155,15 @@ function fakeClearTimeout(id?: unknown) { } } -const fakeSetInterval: typeof globalThis.setInterval = function ( - callback, +function fakeSetInterval( + callback: string | ((...args: unknown[]) => unknown), delay = 0, - ...args -) { + ...args: unknown[] +): number { assertIsCallbackFunction(callback, "setInterval"); if (!time) throw new TimeError("Cannot set interval: time is not faked"); return setTimer(callback, delay, args, true); -}; +} function fakeClearInterval(id?: unknown) { if (!time) throw new TimeError("Cannot clear interval: time is not faked"); @@ -173,8 +173,7 @@ function fakeClearInterval(id?: unknown) { } function setTimer( - // deno-lint-ignore no-explicit-any - callback: (...args: any[]) => void, + callback: (...args: unknown[]) => unknown, delay = 0, args: unknown[], repeat = false, @@ -209,9 +208,11 @@ function fakeAbortSignalTimeout(delay: number): AbortSignal { function overrideGlobals() { globalThis.Date = FakeDate; - globalThis.setTimeout = fakeSetTimeout; + globalThis.setTimeout = + fakeSetTimeout as unknown as typeof globalThis.setTimeout; globalThis.clearTimeout = fakeClearTimeout; - globalThis.setInterval = fakeSetInterval; + globalThis.setInterval = + fakeSetInterval as unknown as typeof globalThis.setInterval; globalThis.clearInterval = fakeClearInterval; AbortSignal.timeout = fakeAbortSignalTimeout; } @@ -245,7 +246,7 @@ let now: number; let initializedAt: number; let advanceRate: number; let advanceFrequency: number; -let advanceIntervalId: number | undefined; +let advanceIntervalId: ReturnType | undefined; let timerId: Generator; let dueNodes: Map; let dueTree: RedBlackTree; @@ -265,7 +266,7 @@ let dueTree: RedBlackTree; * } from "@std/testing/mock"; * import { FakeTime } from "@std/testing/time"; * - * function secondInterval(cb: () => void): number { + * function secondInterval(cb: () => void) { * return setInterval(cb, 1000); * } * @@ -575,7 +576,7 @@ export class FakeTime { ); } return await new Promise((resolve, reject) => { - let timer: number | null = null; + let timer: ReturnType | null = null; const abort = () => FakeTime .restoreFor(() => { @@ -629,7 +630,7 @@ export class FakeTime { * } from "@std/testing/mock"; * import { FakeTime } from "@std/testing/time"; * - * function secondInterval(cb: () => void): number { + * function secondInterval(cb: () => void) { * return setInterval(cb, 1000); * } * diff --git a/testing/time_test.ts b/testing/time_test.ts index 176f27de85fd..8414bbf200e0 100644 --- a/testing/time_test.ts +++ b/testing/time_test.ts @@ -163,7 +163,7 @@ Deno.test("FakeTime controls timeouts", () => { setTimeout(cb, 1000, "a"); setTimeout(cb, 1500, "b"); - const timeout: number = setTimeout(cb, 1750, "c"); + const timeout = setTimeout(cb, 1750, "c"); setTimeout(cb, 2000, "d"); time.tick(1250); expected.push({ args: ["a"], returned: 7000 }); @@ -199,7 +199,7 @@ Deno.test("FakeTime controls intervals", () => { const cb = spy(fromNow()); const expected: SpyCall[] = []; - const interval: number = setInterval(cb, 1000); + const interval = setInterval(cb, 1000); time.tick(250); assertEquals(cb.calls, expected); time.tick(250); @@ -226,7 +226,7 @@ Deno.test("FakeTime calls timeout and interval callbacks in correct order", () = const timeoutExpected: SpyCall[] = []; const intervalExpected: SpyCall[] = []; - const interval: number = setInterval(intervalCb, 1000); + const interval = setInterval(intervalCb, 1000); setTimeout(timeoutCb, 500); time.tick(250); assertEquals(intervalCb.calls, intervalExpected); diff --git a/toml/_parser_test.ts b/toml/_parser_test.ts index efa569984e99..a91ea0a614ca 100644 --- a/toml/_parser_test.ts +++ b/toml/_parser_test.ts @@ -489,7 +489,7 @@ Deno.test({ Deno.test({ name: "(private) deepAssign() works correctly", fn() { - const source = { + const source: Record = { foo: { items: [ { @@ -528,7 +528,7 @@ Deno.test({ email: { x: { main: "mail@example.com" }, }, - } as unknown, + }, }, ], },