diff options
author | David Sherret <dsherret@users.noreply.github.com> | 2022-12-15 21:15:25 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-15 21:15:25 -0500 |
commit | 9e977cd6aaabc6618421578654becafa1ab611f5 (patch) | |
tree | 5f5c5fc2799ec46e77d758516e6ad1fb349764ab /cli/tests | |
parent | 28cc18b5168d926577795eaf3974095da2def3e8 (diff) |
fix(npm): improve exports resolution when type checking (#17071)
Closes #17012
Diffstat (limited to 'cli/tests')
9 files changed, 58 insertions, 7 deletions
diff --git a/cli/tests/npm_tests.rs b/cli/tests/npm_tests.rs index 05dc83cfd..07e36850f 100644 --- a/cli/tests/npm_tests.rs +++ b/cli/tests/npm_tests.rs @@ -279,7 +279,7 @@ mod npm { exit_code: 1, }); - itest!(types { + itest!(types_general { args: "check --quiet npm/types/main.ts", output: "npm/types/main.out", envs: env_vars_for_npm_tests(), diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/client.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/client.d.ts new file mode 100644 index 000000000..2d156f5bb --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/client.d.ts @@ -0,0 +1 @@ +export function getClient(): 5; diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/client.mjs b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/client.mjs new file mode 100644 index 000000000..938238d95 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/client.mjs @@ -0,0 +1,3 @@ +export function getClient() { + return 5; +} diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.d.ts new file mode 100644 index 000000000..e18f8b551 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.d.ts @@ -0,0 +1 @@ +export function entryC(): 12; diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.js b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.js new file mode 100644 index 000000000..070b1ccbd --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/dist/entry-c.js @@ -0,0 +1,3 @@ +export function entryC() { + return 12; +} diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-b.d.ts b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-b.d.ts new file mode 100644 index 000000000..79c9c8434 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/entry-b.d.ts @@ -0,0 +1,2 @@ +// it will go to this and not the types entry because this entry was first +export function entryB(): string;
\ No newline at end of file diff --git a/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/package.json b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/package.json new file mode 100644 index 000000000..35a1cd9f5 --- /dev/null +++ b/cli/tests/testdata/npm/registry/@denotest/types-exports-subpaths/1.0.0/package.json @@ -0,0 +1,19 @@ +{ + "name": "@denotest/types-exports-subpaths", + "version": "1.0.0", + "exports": { + "./client": { + "types": { + "default": "./client.d.ts" + }, + "import": "./dist/client.mjs" + }, + "./entry-b": { + "import": "./entry-b.d.ts", + "types": "./dist/entry-b-wrong.d.ts" + }, + "./entry-c": { + "import": "./dist/entry-c.js" + } + } +} diff --git a/cli/tests/testdata/npm/types/main.out b/cli/tests/testdata/npm/types/main.out index c43923478..47d72f74c 100644 --- a/cli/tests/testdata/npm/types/main.out +++ b/cli/tests/testdata/npm/types/main.out @@ -1,7 +1,7 @@ error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. bar: 1, ~~~ - at [WILDCARD]/npm/types/main.ts:7:3 + at [WILDCARD]/npm/types/main.ts:[WILDCARD] The expected type comes from property 'bar' which is declared here on type 'Foobar' bar: string; @@ -11,7 +11,7 @@ error: TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. prop: 1, ~~~~ - at [WILDCARD]/npm/types/main.ts:11:3 + at [WILDCARD]/npm/types/main.ts:[WILDCARD] The expected type comes from property 'prop' which is declared here on type 'SomeInterface' prop: string; @@ -21,7 +21,7 @@ TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. TS2322 [ERROR]: Type 'string' is not assignable to type 'number'. prop2: "asdf", ~~~~~ - at [WILDCARD]/npm/types/main.ts:12:3 + at [WILDCARD]/npm/types/main.ts:[WILDCARD] The expected type comes from property 'prop2' which is declared here on type 'SomeInterface' prop2: number; @@ -31,7 +31,7 @@ TS2322 [ERROR]: Type 'string' is not assignable to type 'number'. TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. fizz: 1, ~~~~ - at [WILDCARD]/npm/types/main.ts:16:3 + at [WILDCARD]/npm/types/main.ts:[WILDCARD] The expected type comes from property 'fizz' which is declared here on type 'Fizzbuzz' fizz: string; @@ -41,11 +41,26 @@ TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. TS2322 [ERROR]: Type 'number' is not assignable to type 'string'. buzz: 2, ~~~~ - at [WILDCARD]/npm/types/main.ts:17:3 + at [WILDCARD]/npm/types/main.ts:[WILDCARD] The expected type comes from property 'buzz' which is declared here on type 'Fizzbuzz' buzz: string; ~~~~ at [WILDCARD]/@denotest/types/1.0.0/index.d.ts:3:3 -Found 5 errors. +TS2322 [ERROR]: Type '5' is not assignable to type '"test1"'. +const valueA: "test1" = getClient(); + ~~~~~~ + at [WILDCARD]/npm/types/main.ts:[WILDCARD] + +TS2322 [ERROR]: Type 'string' is not assignable to type '"test2"'. +const valueB: "test2" = entryB(); + ~~~~~~ + at [WILDCARD]/types/main.ts:[WILDCARD] + +TS2322 [ERROR]: Type '12' is not assignable to type '"test3"'. +const valueC: "test3" = entryC(); + ~~~~~~ + at [WILDCARD]/types/main.ts:[WILDCARD] + +Found 8 errors. diff --git a/cli/tests/testdata/npm/types/main.ts b/cli/tests/testdata/npm/types/main.ts index 324ed723f..fb8b65c98 100644 --- a/cli/tests/testdata/npm/types/main.ts +++ b/cli/tests/testdata/npm/types/main.ts @@ -1,6 +1,9 @@ import type { Fizzbuzz } from "npm:@denotest/types"; import type { SomeInterface } from "npm:@denotest/types_imported"; import type { Foobar as FooInterface } from "npm:@denotest/types_imported/subpath"; +import { getClient } from "npm:@denotest/types-exports-subpaths/client"; +import { entryB } from "npm:@denotest/types-exports-subpaths/entry-b"; +import { entryC } from "npm:@denotest/types-exports-subpaths/entry-c"; const foobar: FooInterface = { foo: "foo", @@ -16,3 +19,7 @@ const fizzbuzz: Fizzbuzz = { fizz: 1, buzz: 2, }; + +const valueA: "test1" = getClient(); +const valueB: "test2" = entryB(); +const valueC: "test3" = entryC(); |