-
Notifications
You must be signed in to change notification settings - Fork 654
Closed
Labels
Description
Describe the bug
testing/time.ts
fails type checking locally (deno task test
from within std
repo) due to setTimeout
and setInterval
types allowing an eval-able string as the first argument, whereas fakeSetTimeout
and fakeSetInterval
don't.
It doesn't seem like this is affecting CI, presumably there's something different in my local TS setup or some bug in Deno LSP causing it?
Steps to Reproduce
deno task test async
# TS2322 [ERROR]: Type '(callback: (...args: any[]) => void, delay?: number, ...args: any[]) => number' is not assignable to type '{ (handler: TimerHandler, timeout?: number | undefined, ...arguments: any[]): number; (cb: (...args: any[]) => void, delay?: number | undefined, ...args: any[]): number; }'.
# Types of parameters 'callback' and 'handler' are incompatible.
# Type 'TimerHandler' is not assignable to type '(...args: any[]) => void'.
# Type 'string' is not assignable to type '(...args: any[]) => void'.
# globalThis.setTimeout = fakeSetTimeout;
# ~~~~~~~~~~~~~~~~~~~~~
# at file:///path/to/std/testing/time.ts:203:3
#
# TS2322 [ERROR]: Type '(callback: (...args: any[]) => unknown, delay?: number, ...args: any[]) => number' is not assignable to type '{ (handler: TimerHandler, timeout?: number | undefined, ...arguments: any[]): number; (cb: (...args: any[]) => void, delay?: number | undefined, ...args: any[]): number; }'.
# Types of parameters 'callback' and 'handler' are incompatible.
# Type 'TimerHandler' is not assignable to type '(...args: any[]) => unknown'.
# Type 'string' is not assignable to type '(...args: any[]) => unknown'.
# globalThis.setInterval = fakeSetInterval;
# ~~~~~~~~~~~~~~~~~~~~~~
# at file:///path/to/std/testing/time.ts:205:3
Expected behavior
Type checking passes. Passing a string as the first argument to the mocked setTimeout
/setInterval
should probably still throw at runtime though (I was surprised to find TS allows this signature at all).
Environment
- OS: WSL2
- deno version: 2.4.2
- std version: async@1.0.13