-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Description
Version: Deno 2.5.4
The value of globalThis.process
exists at runtime but it does not pass type checking. The same is true for the process
global.
Repro
$ # Create a source file that uses globalThis.process
$ echo 'console.log(globalThis.process.argv, process.argv);' > main.ts
$
$ # It runs just fine
$ deno main.ts
[ [Getter], [Getter] ] [ [Getter], [Getter] ]
$
$ # However, it does not type-check:
$ deno check main.ts
Check file:///tmp/repro/main.ts
TS7017 [ERROR]: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.
console.log(globalThis.process.argv, process.argv);
~~~~~~~
at file:///tmp/repro/main.ts:1:24
TS2580 [ERROR]: Cannot find name 'process'.
console.log(globalThis.process.argv, process.argv);
~~~~~~~
at file:///tmp/repro/main.ts:1:38
Found 2 errors.
error: Type checking failed.
$ # When we add an unused import of `node:process`, it is fixed:
$ echo 'import _ from "node:process"' >> main.ts
$ deno check main.ts
Check file:///tmp/repro/main.ts
$
It seems like the types are only available when node:process
is imported, but the runtime values are available always.
Workaround
Add the following line to the source file.
import process from "node:process";
Metadata
Metadata
Assignees
Labels
No labels