Skip to content

Commit 5b3bc60

Browse files
committed
Add tests corresponding to repro from #37928
1 parent 92f41c8 commit 5b3bc60

File tree

5 files changed

+692
-0
lines changed

5 files changed

+692
-0
lines changed

src/testRunner/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
"unittests/tsbuild/amdModulesWithOut.ts",
111111
"unittests/tsbuild/configFileErrors.ts",
112112
"unittests/tsbuild/containerOnlyReferenced.ts",
113+
"unittests/tsbuild/declarationEmit.ts",
113114
"unittests/tsbuild/demo.ts",
114115
"unittests/tsbuild/emitDeclarationOnly.ts",
115116
"unittests/tsbuild/emptyFiles.ts",
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
namespace ts {
2+
describe("unittests:: tsbuild:: declarationEmit", () => {
3+
function getFiles(): vfs.FileSet {
4+
return {
5+
"/src/solution/tsconfig.base.json": JSON.stringify({
6+
compilerOptions: {
7+
rootDir: "./",
8+
outDir: "lib"
9+
}
10+
}),
11+
"/src/solution/tsconfig.json": JSON.stringify({
12+
compilerOptions: { composite: true },
13+
references: [{ path: "./src" }],
14+
include: []
15+
}),
16+
"/src/solution/src/tsconfig.json": JSON.stringify({
17+
compilerOptions: { composite: true },
18+
references: [{ path: "./subProject" }, { path: "./subProject2" }],
19+
include: []
20+
}),
21+
"/src/solution/src/subProject/tsconfig.json": JSON.stringify({
22+
extends: "../../tsconfig.base.json",
23+
compilerOptions: { composite: true },
24+
references: [{ path: "../common" }],
25+
include: ["./index.ts"]
26+
}),
27+
"/src/solution/src/subProject/index.ts": Utils.dedent`
28+
import { Nominal } from '../common/nominal';
29+
export type MyNominal = Nominal<string, 'MyNominal'>;`,
30+
"/src/solution/src/subProject2/tsconfig.json": JSON.stringify({
31+
extends: "../../tsconfig.base.json",
32+
compilerOptions: { composite: true },
33+
references: [{ path: "../subProject" }],
34+
include: ["./index.ts"]
35+
}),
36+
"/src/solution/src/subProject2/index.ts": Utils.dedent`
37+
import { MyNominal } from '../subProject/index';
38+
const variable = {
39+
key: 'value' as MyNominal,
40+
};
41+
export function getVar(): keyof typeof variable {
42+
return 'key';
43+
}`,
44+
"/src/solution/src/common/tsconfig.json": JSON.stringify({
45+
extends: "../../tsconfig.base.json",
46+
compilerOptions: { composite: true },
47+
include: ["./nominal.ts"]
48+
}),
49+
"/src/solution/src/common/nominal.ts": Utils.dedent`
50+
/// <reference path="./types.d.ts" />
51+
export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;`,
52+
"/src/solution/src/common/types.d.ts": Utils.dedent`
53+
declare type MyNominal<T, Name extends string> = T & {
54+
specialKey: Name;
55+
};`,
56+
};
57+
}
58+
verifyTsc({
59+
scenario: "declarationEmit",
60+
subScenario: "when declaration file is referenced through triple slash",
61+
fs: () => loadProjectFromFiles(getFiles()),
62+
commandLineArgs: ["--b", "/src/solution/tsconfig.json", "--verbose"]
63+
});
64+
65+
verifyTsc({
66+
scenario: "declarationEmit",
67+
subScenario: "when declaration file is referenced through triple slash and uses baseUrl",
68+
fs: () => loadProjectFromFiles({
69+
...getFiles(),
70+
"/src/solution/src/common/tsconfig.json": JSON.stringify({
71+
extends: "../../tsconfig.base.json",
72+
compilerOptions: { composite: true, baseUrl: "./" },
73+
include: ["./nominal.ts"]
74+
}),
75+
}),
76+
commandLineArgs: ["--b", "/src/solution/tsconfig.json", "--verbose"]
77+
});
78+
79+
verifyTsc({
80+
scenario: "declarationEmit",
81+
subScenario: "when declaration file is referenced through triple slash but uses no references",
82+
fs: () => loadProjectFromFiles({
83+
...getFiles(),
84+
"/src/solution/tsconfig.json": JSON.stringify({
85+
extends: "./tsconfig.base.json",
86+
compilerOptions: { composite: true },
87+
include: ["./src/**/*.ts"]
88+
}),
89+
}),
90+
commandLineArgs: ["--b", "/src/solution/tsconfig.json", "--verbose"]
91+
});
92+
});
93+
}
Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
Input::
2+
//// [/lib/lib.d.ts]
3+
/// <reference no-default-lib="true"/>
4+
interface Boolean {}
5+
interface Function {}
6+
interface CallableFunction {}
7+
interface NewableFunction {}
8+
interface IArguments {}
9+
interface Number { toExponential: any; }
10+
interface Object {}
11+
interface RegExp {}
12+
interface String { charAt: any; }
13+
interface Array<T> { length: number; [n: number]: T; }
14+
interface ReadonlyArray<T> {}
15+
declare const console: { log(msg: any): void; };
16+
17+
//// [/src/solution/src/common/nominal.ts]
18+
/// <reference path="./types.d.ts" />
19+
export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;
20+
21+
//// [/src/solution/src/common/tsconfig.json]
22+
{"extends":"../../tsconfig.base.json","compilerOptions":{"composite":true,"baseUrl":"./"},"include":["./nominal.ts"]}
23+
24+
//// [/src/solution/src/common/types.d.ts]
25+
declare type MyNominal<T, Name extends string> = T & {
26+
specialKey: Name;
27+
};
28+
29+
//// [/src/solution/src/subProject/index.ts]
30+
import { Nominal } from '../common/nominal';
31+
export type MyNominal = Nominal<string, 'MyNominal'>;
32+
33+
//// [/src/solution/src/subProject/tsconfig.json]
34+
{"extends":"../../tsconfig.base.json","compilerOptions":{"composite":true},"references":[{"path":"../common"}],"include":["./index.ts"]}
35+
36+
//// [/src/solution/src/subProject2/index.ts]
37+
38+
39+
//// [/src/solution/src/subProject2/tsconfig.json]
40+
{"extends":"../../tsconfig.base.json","compilerOptions":{"composite":true},"references":[{"path":"../subProject"}],"include":["./index.ts"]}
41+
42+
//// [/src/solution/src/tsconfig.json]
43+
{"compilerOptions":{"composite":true},"references":[{"path":"./subProject"},{"path":"./subProject2"}],"include":[]}
44+
45+
//// [/src/solution/tsconfig.base.json]
46+
{"compilerOptions":{"rootDir":"./","outDir":"lib"}}
47+
48+
//// [/src/solution/tsconfig.json]
49+
{"compilerOptions":{"composite":true},"references":[{"path":"./src"}],"include":[]}
50+
51+
52+
53+
Output::
54+
/lib/tsc --b /src/solution/tsconfig.json --verbose
55+
[12:00:00 AM] Projects in this build:
56+
* src/solution/src/common/tsconfig.json
57+
* src/solution/src/subProject/tsconfig.json
58+
* src/solution/src/subProject2/tsconfig.json
59+
* src/solution/src/tsconfig.json
60+
* src/solution/tsconfig.json
61+
62+
[12:00:00 AM] Project 'src/solution/src/common/tsconfig.json' is out of date because output file 'src/solution/lib/src/common/nominal.js' does not exist
63+
64+
[12:00:00 AM] Building project '/src/solution/src/common/tsconfig.json'...
65+
66+
[12:00:00 AM] Project 'src/solution/src/subProject/tsconfig.json' is out of date because output file 'src/solution/lib/src/subProject/index.js' does not exist
67+
68+
[12:00:00 AM] Building project '/src/solution/src/subProject/tsconfig.json'...
69+
70+
src/solution/lib/src/common/nominal.d.ts:2:55 - error TS2304: Cannot find name 'MyNominal'.
71+
72+
2 export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;
73+
   ~~~~~~~~~
74+
75+
src/solution/lib/src/common/nominal.d.ts:1:23 - error TS2688: Cannot find type definition file for 'types'.
76+
77+
1 /// <reference types="types" />
78+
   ~~~~~
79+
80+
[12:00:00 AM] Project 'src/solution/src/subProject2/tsconfig.json' can't be built because its dependency 'src/solution/src/subProject' has errors
81+
82+
[12:00:00 AM] Skipping build of project '/src/solution/src/subProject2/tsconfig.json' because its dependency '/src/solution/src/subProject' has errors
83+
84+
85+
Found 2 errors.
86+
87+
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated
88+
89+
90+
//// [/src/solution/lib/src/common/nominal.d.ts]
91+
/// <reference types="types" />
92+
export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;
93+
94+
95+
//// [/src/solution/lib/src/common/nominal.js]
96+
"use strict";
97+
exports.__esModule = true;
98+
/// <reference path="./types.d.ts" />
99+
100+
101+
//// [/src/solution/lib/src/common/tsconfig.tsbuildinfo]
102+
{
103+
"program": {
104+
"fileInfos": {
105+
"../../../../../lib/lib.d.ts": {
106+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
107+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
108+
"affectsGlobalScope": true
109+
},
110+
"../../../src/common/types.d.ts": {
111+
"version": "23815050294-declare type MyNominal<T, Name extends string> = T & {\n specialKey: Name;\n};",
112+
"signature": "23815050294-declare type MyNominal<T, Name extends string> = T & {\n specialKey: Name;\n};",
113+
"affectsGlobalScope": true
114+
},
115+
"../../../src/common/nominal.ts": {
116+
"version": "4107369137-/// <reference path=\"./types.d.ts\" />\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;",
117+
"signature": "-2060908103-/// <reference types=\"types\" />\r\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;\r\n",
118+
"affectsGlobalScope": false
119+
}
120+
},
121+
"options": {
122+
"rootDir": "../../..",
123+
"outDir": "../..",
124+
"composite": true,
125+
"baseUrl": "../../../src/common",
126+
"configFilePath": "../../../src/common/tsconfig.json"
127+
},
128+
"referencedMap": {
129+
"../../../src/common/nominal.ts": [
130+
"../../../src/common/types.d.ts"
131+
]
132+
},
133+
"exportedModulesMap": {},
134+
"semanticDiagnosticsPerFile": [
135+
"../../../../../lib/lib.d.ts",
136+
"../../../src/common/nominal.ts",
137+
"../../../src/common/types.d.ts"
138+
]
139+
},
140+
"version": "FakeTSVersion"
141+
}
142+
143+
//// [/src/solution/lib/src/subProject/tsconfig.tsbuildinfo]
144+
{
145+
"program": {
146+
"fileInfos": {
147+
"../../../../../lib/lib.d.ts": {
148+
"version": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
149+
"signature": "3858781397-/// <reference no-default-lib=\"true\"/>\ninterface Boolean {}\ninterface Function {}\ninterface CallableFunction {}\ninterface NewableFunction {}\ninterface IArguments {}\ninterface Number { toExponential: any; }\ninterface Object {}\ninterface RegExp {}\ninterface String { charAt: any; }\ninterface Array<T> { length: number; [n: number]: T; }\ninterface ReadonlyArray<T> {}\ndeclare const console: { log(msg: any): void; };",
150+
"affectsGlobalScope": true
151+
},
152+
"../common/nominal.d.ts": {
153+
"version": "-2060908103-/// <reference types=\"types\" />\r\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;\r\n",
154+
"signature": "-2060908103-/// <reference types=\"types\" />\r\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;\r\n",
155+
"affectsGlobalScope": false
156+
},
157+
"../../../src/subproject/index.ts": {
158+
"version": "-25117049605-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal<string, 'MyNominal'>;",
159+
"signature": "-21416888433-import { Nominal } from '../common/nominal';\r\nexport declare type MyNominal = Nominal<string, 'MyNominal'>;\r\n",
160+
"affectsGlobalScope": false
161+
}
162+
},
163+
"options": {
164+
"rootDir": "../../..",
165+
"outDir": "../..",
166+
"composite": true,
167+
"configFilePath": "../../../src/subProject/tsconfig.json"
168+
},
169+
"referencedMap": {
170+
"../../../src/subproject/index.ts": [
171+
"../common/nominal.d.ts"
172+
]
173+
},
174+
"exportedModulesMap": {
175+
"../../../src/subproject/index.ts": [
176+
"../common/nominal.d.ts"
177+
]
178+
},
179+
"semanticDiagnosticsPerFile": [
180+
"../../../../../lib/lib.d.ts",
181+
[
182+
"../common/nominal.d.ts",
183+
[
184+
{
185+
"file": "../common/nominal.d.ts",
186+
"start": 87,
187+
"length": 9,
188+
"messageText": "Cannot find name 'MyNominal'.",
189+
"category": 1,
190+
"code": 2304
191+
}
192+
]
193+
],
194+
"../../../src/subproject/index.ts"
195+
],
196+
"affectedFilesPendingEmit": [
197+
[
198+
"../common/nominal.d.ts",
199+
1
200+
],
201+
[
202+
"../../../src/subproject/index.ts",
203+
1
204+
]
205+
]
206+
},
207+
"version": "FakeTSVersion"
208+
}
209+

0 commit comments

Comments
 (0)