-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Description
Deno version
deno 2.7.5 (stable, release, aarch64-apple-darwin)
v8 14.6.202.9-rusty
typescript 5.9.2
Problem description
When using certain npm packages in Deno, deno check fails with type errors related to global types like RequestInit and setTimeout, even though the code runs perfectly with deno run. It seems like Deno is confusing its own Web API globals with Node.js types from @types/node when resolving types for npm dependencies.
Case 1: RequestInit in npm:ky
When using ky, the body property is reported as missing from its Options type, even though Options extends RequestInit.
Reproduction:
import ky from "npm:ky";
const res = await ky.post(
"https://httpbin.org/anything",
{
body: "hello",
},
).text();
console.log(res);Error Output:
Check ky-demo.ts
TS2353 [ERROR]: Object literal may only specify known properties, and 'body' does not exist in type 'Options'.
body: "hello",
~~~~
at ky-demo.ts:6:9
error: Type checking failed.
Case 2: setTimeout in npm:@solid-primitives/timer
Passing Deno's global setTimeout to a function that expects typeof setTimeout from an npm package fails because it expects the Node.js version of setTimeout (which has __promisify__).
Reproduction:
import { makeTimer } from "npm:@solid-primitives/timer";
const clear = makeTimer(() => {
console.log("tick");
}, 1000, setTimeout);
clear();
console.log("OK");Error Output:
Check repro_timer.ts
TS2345 [ERROR]: Argument of type '(cb: string | ((...args: any[]) => void), delay?: number | undefined, ...args: any[]) => number' is not assignable to parameter of type 'typeof setTimeout | { <TArgs extends any[]>(callback: (...args: TArgs) => void, delay?: number | undefined, ...args: TArgs): Timeout; (callback: (_: void) => void, delay?: number | undefined): Timeout; }'.
Property '__promisify__' is missing in type '(cb: string | ((...args: any[]) => void), delay?: number | undefined, ...args: any[]) => number' but required in type 'typeof setTimeout'.
}, 1000, setTimeout);
~~~~~~~~~~
at repro_timer.ts:5:10
'__promisify__' is declared here.
export { __promisify__ };
~~~~~~~~~~~~~
at asset:///node/timers.d.cts:239:22
Expected behavior
deno check should correctly map npm package type references to Deno's built-in global types when they refer to standard Web API globals, or handle the @types/node vs Deno global conflict more gracefully. Both examples work at runtime but fail type checking.