-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Triple slash references must resolve against the resolved file name (.d.ts and not original source file) since they are rewritten in the .d.ts emit #39645
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
namespace ts { | ||
describe("unittests:: tsbuild:: declarationEmit", () => { | ||
function getFiles(): vfs.FileSet { | ||
return { | ||
"/src/solution/tsconfig.base.json": JSON.stringify({ | ||
compilerOptions: { | ||
rootDir: "./", | ||
outDir: "lib" | ||
} | ||
}), | ||
"/src/solution/tsconfig.json": JSON.stringify({ | ||
compilerOptions: { composite: true }, | ||
references: [{ path: "./src" }], | ||
include: [] | ||
}), | ||
"/src/solution/src/tsconfig.json": JSON.stringify({ | ||
compilerOptions: { composite: true }, | ||
references: [{ path: "./subProject" }, { path: "./subProject2" }], | ||
include: [] | ||
}), | ||
"/src/solution/src/subProject/tsconfig.json": JSON.stringify({ | ||
extends: "../../tsconfig.base.json", | ||
compilerOptions: { composite: true }, | ||
references: [{ path: "../common" }], | ||
include: ["./index.ts"] | ||
}), | ||
"/src/solution/src/subProject/index.ts": Utils.dedent` | ||
import { Nominal } from '../common/nominal'; | ||
export type MyNominal = Nominal<string, 'MyNominal'>;`, | ||
"/src/solution/src/subProject2/tsconfig.json": JSON.stringify({ | ||
extends: "../../tsconfig.base.json", | ||
compilerOptions: { composite: true }, | ||
references: [{ path: "../subProject" }], | ||
include: ["./index.ts"] | ||
}), | ||
"/src/solution/src/subProject2/index.ts": Utils.dedent` | ||
import { MyNominal } from '../subProject/index'; | ||
const variable = { | ||
key: 'value' as MyNominal, | ||
}; | ||
export function getVar(): keyof typeof variable { | ||
return 'key'; | ||
}`, | ||
"/src/solution/src/common/tsconfig.json": JSON.stringify({ | ||
extends: "../../tsconfig.base.json", | ||
compilerOptions: { composite: true }, | ||
include: ["./nominal.ts"] | ||
}), | ||
"/src/solution/src/common/nominal.ts": Utils.dedent` | ||
/// <reference path="./types.d.ts" /> | ||
export declare type Nominal<T, Name extends string> = MyNominal<T, Name>;`, | ||
"/src/solution/src/common/types.d.ts": Utils.dedent` | ||
declare type MyNominal<T, Name extends string> = T & { | ||
specialKey: Name; | ||
};`, | ||
}; | ||
} | ||
verifyTsc({ | ||
scenario: "declarationEmit", | ||
subScenario: "when declaration file is referenced through triple slash", | ||
fs: () => loadProjectFromFiles(getFiles()), | ||
commandLineArgs: ["--b", "/src/solution/tsconfig.json", "--verbose"] | ||
}); | ||
|
||
verifyTsc({ | ||
scenario: "declarationEmit", | ||
subScenario: "when declaration file is referenced through triple slash and uses baseUrl", | ||
fs: () => loadProjectFromFiles({ | ||
...getFiles(), | ||
"/src/solution/src/common/tsconfig.json": JSON.stringify({ | ||
extends: "../../tsconfig.base.json", | ||
compilerOptions: { composite: true, baseUrl: "./" }, | ||
include: ["./nominal.ts"] | ||
}), | ||
}), | ||
commandLineArgs: ["--b", "/src/solution/tsconfig.json", "--verbose"] | ||
}); | ||
|
||
verifyTsc({ | ||
scenario: "declarationEmit", | ||
subScenario: "when declaration file is referenced through triple slash but uses no references", | ||
fs: () => loadProjectFromFiles({ | ||
...getFiles(), | ||
"/src/solution/tsconfig.json": JSON.stringify({ | ||
extends: "./tsconfig.base.json", | ||
compilerOptions: { composite: true }, | ||
include: ["./src/**/*.ts"] | ||
}), | ||
}), | ||
commandLineArgs: ["--b", "/src/solution/tsconfig.json", "--verbose"] | ||
}); | ||
}); | ||
} |
209 changes: 209 additions & 0 deletions
209
...nitial-build/when-declaration-file-is-referenced-through-triple-slash-and-uses-baseUrl.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
Input:: | ||
//// [/lib/lib.d.ts] | ||
/// <reference no-default-lib="true"/> | ||
interface Boolean {} | ||
interface Function {} | ||
interface CallableFunction {} | ||
interface NewableFunction {} | ||
interface IArguments {} | ||
interface Number { toExponential: any; } | ||
interface Object {} | ||
interface RegExp {} | ||
interface String { charAt: any; } | ||
interface Array<T> { length: number; [n: number]: T; } | ||
interface ReadonlyArray<T> {} | ||
declare const console: { log(msg: any): void; }; | ||
|
||
//// [/src/solution/src/common/nominal.ts] | ||
/// <reference path="./types.d.ts" /> | ||
export declare type Nominal<T, Name extends string> = MyNominal<T, Name>; | ||
|
||
//// [/src/solution/src/common/tsconfig.json] | ||
{"extends":"../../tsconfig.base.json","compilerOptions":{"composite":true,"baseUrl":"./"},"include":["./nominal.ts"]} | ||
|
||
//// [/src/solution/src/common/types.d.ts] | ||
declare type MyNominal<T, Name extends string> = T & { | ||
specialKey: Name; | ||
}; | ||
|
||
//// [/src/solution/src/subProject/index.ts] | ||
import { Nominal } from '../common/nominal'; | ||
export type MyNominal = Nominal<string, 'MyNominal'>; | ||
|
||
//// [/src/solution/src/subProject/tsconfig.json] | ||
{"extends":"../../tsconfig.base.json","compilerOptions":{"composite":true},"references":[{"path":"../common"}],"include":["./index.ts"]} | ||
|
||
//// [/src/solution/src/subProject2/index.ts] | ||
|
||
|
||
//// [/src/solution/src/subProject2/tsconfig.json] | ||
{"extends":"../../tsconfig.base.json","compilerOptions":{"composite":true},"references":[{"path":"../subProject"}],"include":["./index.ts"]} | ||
|
||
//// [/src/solution/src/tsconfig.json] | ||
{"compilerOptions":{"composite":true},"references":[{"path":"./subProject"},{"path":"./subProject2"}],"include":[]} | ||
|
||
//// [/src/solution/tsconfig.base.json] | ||
{"compilerOptions":{"rootDir":"./","outDir":"lib"}} | ||
|
||
//// [/src/solution/tsconfig.json] | ||
{"compilerOptions":{"composite":true},"references":[{"path":"./src"}],"include":[]} | ||
|
||
|
||
|
||
Output:: | ||
/lib/tsc --b /src/solution/tsconfig.json --verbose | ||
[[90m12:00:00 AM[0m] Projects in this build: | ||
* src/solution/src/common/tsconfig.json | ||
* src/solution/src/subProject/tsconfig.json | ||
* src/solution/src/subProject2/tsconfig.json | ||
* src/solution/src/tsconfig.json | ||
* src/solution/tsconfig.json | ||
|
||
[[90m12:00:00 AM[0m] Project 'src/solution/src/common/tsconfig.json' is out of date because output file 'src/solution/lib/src/common/nominal.js' does not exist | ||
|
||
[[90m12:00:00 AM[0m] Building project '/src/solution/src/common/tsconfig.json'... | ||
|
||
[[90m12:00:00 AM[0m] Project 'src/solution/src/subProject/tsconfig.json' is out of date because output file 'src/solution/lib/src/subProject/index.js' does not exist | ||
|
||
[[90m12:00:00 AM[0m] Building project '/src/solution/src/subProject/tsconfig.json'... | ||
|
||
[96msrc/solution/lib/src/common/nominal.d.ts[0m:[93m2[0m:[93m55[0m - [91merror[0m[90m TS2304: [0mCannot find name 'MyNominal'. | ||
|
||
[7m2[0m export declare type Nominal<T, Name extends string> = MyNominal<T, Name>; | ||
[7m [0m [91m ~~~~~~~~~[0m | ||
|
||
[96msrc/solution/lib/src/common/nominal.d.ts[0m:[93m1[0m:[93m23[0m - [91merror[0m[90m TS2688: [0mCannot find type definition file for 'types'. | ||
|
||
[7m1[0m /// <reference types="types" /> | ||
[7m [0m [91m ~~~~~[0m | ||
|
||
[[90m12:00:00 AM[0m] Project 'src/solution/src/subProject2/tsconfig.json' can't be built because its dependency 'src/solution/src/subProject' has errors | ||
|
||
[[90m12:00:00 AM[0m] Skipping build of project '/src/solution/src/subProject2/tsconfig.json' because its dependency '/src/solution/src/subProject' has errors | ||
|
||
|
||
Found 2 errors. | ||
|
||
exitCode:: ExitStatus.DiagnosticsPresent_OutputsGenerated | ||
|
||
|
||
//// [/src/solution/lib/src/common/nominal.d.ts] | ||
/// <reference types="types" /> | ||
export declare type Nominal<T, Name extends string> = MyNominal<T, Name>; | ||
|
||
|
||
//// [/src/solution/lib/src/common/nominal.js] | ||
"use strict"; | ||
exports.__esModule = true; | ||
/// <reference path="./types.d.ts" /> | ||
|
||
|
||
//// [/src/solution/lib/src/common/tsconfig.tsbuildinfo] | ||
{ | ||
"program": { | ||
"fileInfos": { | ||
"../../../../../lib/lib.d.ts": { | ||
"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; };", | ||
"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; };", | ||
"affectsGlobalScope": true | ||
}, | ||
"../../../src/common/types.d.ts": { | ||
"version": "23815050294-declare type MyNominal<T, Name extends string> = T & {\n specialKey: Name;\n};", | ||
"signature": "23815050294-declare type MyNominal<T, Name extends string> = T & {\n specialKey: Name;\n};", | ||
"affectsGlobalScope": true | ||
}, | ||
"../../../src/common/nominal.ts": { | ||
"version": "4107369137-/// <reference path=\"./types.d.ts\" />\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;", | ||
"signature": "-2060908103-/// <reference types=\"types\" />\r\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;\r\n", | ||
"affectsGlobalScope": false | ||
} | ||
}, | ||
"options": { | ||
"rootDir": "../../..", | ||
"outDir": "../..", | ||
"composite": true, | ||
"baseUrl": "../../../src/common", | ||
"configFilePath": "../../../src/common/tsconfig.json" | ||
}, | ||
"referencedMap": { | ||
"../../../src/common/nominal.ts": [ | ||
"../../../src/common/types.d.ts" | ||
] | ||
}, | ||
"exportedModulesMap": {}, | ||
"semanticDiagnosticsPerFile": [ | ||
"../../../../../lib/lib.d.ts", | ||
"../../../src/common/nominal.ts", | ||
"../../../src/common/types.d.ts" | ||
] | ||
}, | ||
"version": "FakeTSVersion" | ||
} | ||
|
||
//// [/src/solution/lib/src/subProject/tsconfig.tsbuildinfo] | ||
{ | ||
"program": { | ||
"fileInfos": { | ||
"../../../../../lib/lib.d.ts": { | ||
"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; };", | ||
"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; };", | ||
"affectsGlobalScope": true | ||
}, | ||
"../common/nominal.d.ts": { | ||
"version": "-2060908103-/// <reference types=\"types\" />\r\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;\r\n", | ||
"signature": "-2060908103-/// <reference types=\"types\" />\r\nexport declare type Nominal<T, Name extends string> = MyNominal<T, Name>;\r\n", | ||
"affectsGlobalScope": false | ||
}, | ||
"../../../src/subproject/index.ts": { | ||
"version": "-25117049605-import { Nominal } from '../common/nominal';\nexport type MyNominal = Nominal<string, 'MyNominal'>;", | ||
"signature": "-21416888433-import { Nominal } from '../common/nominal';\r\nexport declare type MyNominal = Nominal<string, 'MyNominal'>;\r\n", | ||
"affectsGlobalScope": false | ||
} | ||
}, | ||
"options": { | ||
"rootDir": "../../..", | ||
"outDir": "../..", | ||
"composite": true, | ||
"configFilePath": "../../../src/subProject/tsconfig.json" | ||
}, | ||
"referencedMap": { | ||
"../../../src/subproject/index.ts": [ | ||
"../common/nominal.d.ts" | ||
] | ||
}, | ||
"exportedModulesMap": { | ||
"../../../src/subproject/index.ts": [ | ||
"../common/nominal.d.ts" | ||
] | ||
}, | ||
"semanticDiagnosticsPerFile": [ | ||
"../../../../../lib/lib.d.ts", | ||
[ | ||
"../common/nominal.d.ts", | ||
[ | ||
{ | ||
"file": "../common/nominal.d.ts", | ||
"start": 87, | ||
"length": 9, | ||
"messageText": "Cannot find name 'MyNominal'.", | ||
"category": 1, | ||
"code": 2304 | ||
} | ||
] | ||
], | ||
"../../../src/subproject/index.ts" | ||
], | ||
"affectedFilesPendingEmit": [ | ||
[ | ||
"../common/nominal.d.ts", | ||
1 | ||
], | ||
[ | ||
"../../../src/subproject/index.ts", | ||
1 | ||
] | ||
] | ||
}, | ||
"version": "FakeTSVersion" | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.