From fc2e00152b162280e78b06028d51274e33275629 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 24 Jan 2023 15:05:54 +0100 Subject: feat: support node built-in module imports (#17264) Co-authored-by: David Sherret --- cli/tests/testdata/check/node_builtin_modules/mod.js | 3 +++ cli/tests/testdata/check/node_builtin_modules/mod.js.out | 5 +++++ cli/tests/testdata/check/node_builtin_modules/mod.ts | 9 +++++++++ cli/tests/testdata/check/node_builtin_modules/mod.ts.out | 13 +++++++++++++ 4 files changed, 30 insertions(+) create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.js create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.js.out create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.ts create mode 100644 cli/tests/testdata/check/node_builtin_modules/mod.ts.out (limited to 'cli/tests/testdata/check') diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.js b/cli/tests/testdata/check/node_builtin_modules/mod.js new file mode 100644 index 000000000..196fb9be9 --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.js @@ -0,0 +1,3 @@ +// @ts-check +import fs from "node:fs"; +const _data = fs.readFileSync("./node_builtin.js", 123); diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.js.out b/cli/tests/testdata/check/node_builtin_modules/mod.js.out new file mode 100644 index 000000000..97786ebae --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.js.out @@ -0,0 +1,5 @@ +error: TS2769 [ERROR]: No overload matches this call. + [WILDCARD] +const _data = fs.readFileSync("./node_builtin.js", 123); + ~~~ + at file:///[WILDCARD]/node_builtin_modules/mod.js:3:52 diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.ts b/cli/tests/testdata/check/node_builtin_modules/mod.ts new file mode 100644 index 000000000..0e62353fe --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.ts @@ -0,0 +1,9 @@ +import fs from "node:fs"; +const _data = fs.readFileSync("./node_builtin.js", 123); + +// check node:module specifically because for deno check it should +// resolve to the @types/node package, but at runtime it uses a different +// builtin object than deno_std +import { builtinModules } from "node:module"; +// should error about being string[] +const _testString: number[] = builtinModules; diff --git a/cli/tests/testdata/check/node_builtin_modules/mod.ts.out b/cli/tests/testdata/check/node_builtin_modules/mod.ts.out new file mode 100644 index 000000000..49b762cff --- /dev/null +++ b/cli/tests/testdata/check/node_builtin_modules/mod.ts.out @@ -0,0 +1,13 @@ +error: TS2769 [ERROR]: No overload matches this call. + [WILDCARD] +const _data = fs.readFileSync("./node_builtin.js", 123); + ~~~ + at file:///[WILDCARD]/node_builtin_modules/mod.ts:2:52 + +TS2322 [ERROR]: Type 'string[]' is not assignable to type 'number[]'. + Type 'string' is not assignable to type 'number'. +const _testString: number[] = builtinModules; + ~~~~~~~~~~~ + at file:///[WILDCARD]/node_builtin_modules/mod.ts:9:7 + +Found 2 errors. -- cgit v1.2.3