Skip to content

testing/time.ts fails type checking locally due to setTimeout and setInterval types allowing eval-able string arg #6766

@lionel-rowe

Description

@lionel-rowe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions