Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tsc/internal/compiler/projectreferenceparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ func (p *projectReferenceParser) initMapperWorker(ctx context.Context, tasks []*
continue
}
p.loader.projectReferences.configToProjectReference[path] = task.resolved
if task.resolved != nil && p.loader.projectReferences.config.ConfigFile != task.resolved.ConfigFile {
// A cycle can resolve the root config to a different parsed object.
if task.resolved != nil && path != p.loader.projectReferences.rootConfigPath() {
// Map current task's files first, before recursing into subtasks.
// This matches TypeScript's behavior where child project references
// overwrite parent entries when a file belongs to multiple projects.
Expand Down
20 changes: 20 additions & 0 deletions tsc/internal/execute/tsctests/tsc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4580,6 +4580,26 @@ func TestTscNoEmitOnError(t *testing.T) {
func TestTscProjectReferences(t *testing.T) {
t.Parallel()
cases := []tscInput{
{
subScenario: "noEmit checks source files when the project references itself",
files: FileMap{
"/home/src/workspaces/solution/project/index.ts": `export const value: number = "error";`,
"/home/src/workspaces/solution/project/tsconfig.json": `{"compilerOptions":{"composite":true},"references":[{"path":"."}]}`,
},
cwd: "/home/src/workspaces/solution",
commandLineArgs: []string{"-p", "project", "--noEmit", "--pretty", "false"},
},
{
subScenario: "noEmit checks source files when a referenced project references the root project",
files: FileMap{
"/home/src/workspaces/solution/project/index.ts": `export const value: number = "error";`,
"/home/src/workspaces/solution/project/tsconfig.json": `{"compilerOptions":{"composite":true},"references":[{"path":"../other"}]}`,
"/home/src/workspaces/solution/other/index.ts": `export const value = 1;`,
"/home/src/workspaces/solution/other/tsconfig.json": `{"compilerOptions":{"composite":true},"references":[{"path":"../project"}]}`,
},
cwd: "/home/src/workspaces/solution",
commandLineArgs: []string{"-p", "project", "--noEmit", "--pretty", "false"},
},
{
subScenario: "when project references composite project with noEmit",
files: FileMap{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
currentDirectory::/home/src/workspaces/solution
useCaseSensitiveFileNames::true
Input::
//// [/home/src/workspaces/solution/other/index.ts] *new*
export const value = 1;
//// [/home/src/workspaces/solution/other/tsconfig.json] *new*
{"compilerOptions":{"composite":true},"references":[{"path":"../project"}]}
//// [/home/src/workspaces/solution/project/index.ts] *new*
export const value: number = "error";
//// [/home/src/workspaces/solution/project/tsconfig.json] *new*
{"compilerOptions":{"composite":true},"references":[{"path":"../other"}]}

tsc -p project --noEmit --pretty false
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
project/index.ts(1,14): error TS2322: Type 'string' is not assignable to type 'number'.
//// [/home/src/tslibs/TS/Lib/lib.es2026.full.d.ts] *Lib*
/// <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> {}
interface SymbolConstructor {
(desc?: string | number): symbol;
for(name: string): symbol;
readonly toStringTag: symbol;
}
declare var Symbol: SymbolConstructor;
interface Symbol {
readonly [Symbol.toStringTag]: string;
}
declare const console: { log(msg: any): void; };
//// [/home/src/workspaces/solution/project/tsconfig.tsbuildinfo] *new*
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.es2026.full.d.ts","./index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"282b6100cd3f6e9ff84f94bb8aee9402-export const value: number = \"error\";"],"options":{"composite":true},"semanticDiagnosticsPerFile":[[2,[{"pos":13,"end":18,"code":2322,"category":1,"messageKey":"Type_0_is_not_assignable_to_type_1_2322","messageArgs":["string","number"]}]]],"affectedFilesPendingEmit":[2],"emitSignatures":[2]}
//// [/home/src/workspaces/solution/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
"root": [
{
"files": [
"./index.ts"
],
"original": 2
}
],
"fileNames": [
"lib.es2026.full.d.ts",
"./index.ts"
],
"fileInfos": [
{
"fileName": "lib.es2026.full.d.ts",
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": "CommonJS",
"original": {
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": 1
}
},
{
"fileName": "./index.ts",
"version": "282b6100cd3f6e9ff84f94bb8aee9402-export const value: number = \"error\";",
"signature": "282b6100cd3f6e9ff84f94bb8aee9402-export const value: number = \"error\";",
"impliedNodeFormat": "CommonJS"
}
],
"options": {
"composite": true
},
"semanticDiagnosticsPerFile": [
[
"./index.ts",
[
{
"pos": 13,
"end": 18,
"code": 2322,
"category": 1,
"messageKey": "Type_0_is_not_assignable_to_type_1_2322",
"messageArgs": [
"string",
"number"
]
}
]
]
],
"affectedFilesPendingEmit": [
[
"./index.ts",
"Js|Dts",
2
]
],
"emitSignatures": [
{
"file": "./index.ts",
"original": 2
}
],
"size": 1199
}

project/tsconfig.json::
SemanticDiagnostics::
*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts
*refresh* /home/src/workspaces/solution/project/index.ts
Signatures::
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
currentDirectory::/home/src/workspaces/solution
useCaseSensitiveFileNames::true
Input::
//// [/home/src/workspaces/solution/project/index.ts] *new*
export const value: number = "error";
//// [/home/src/workspaces/solution/project/tsconfig.json] *new*
{"compilerOptions":{"composite":true},"references":[{"path":"."}]}

tsc -p project --noEmit --pretty false
ExitStatus:: DiagnosticsPresent_OutputsGenerated
Output::
project/index.ts(1,14): error TS2322: Type 'string' is not assignable to type 'number'.
//// [/home/src/tslibs/TS/Lib/lib.es2026.full.d.ts] *Lib*
/// <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> {}
interface SymbolConstructor {
(desc?: string | number): symbol;
for(name: string): symbol;
readonly toStringTag: symbol;
}
declare var Symbol: SymbolConstructor;
interface Symbol {
readonly [Symbol.toStringTag]: string;
}
declare const console: { log(msg: any): void; };
//// [/home/src/workspaces/solution/project/tsconfig.tsbuildinfo] *new*
{"version":"FakeTSVersion","root":[2],"fileNames":["lib.es2026.full.d.ts","./index.ts"],"fileInfos":[{"version":"8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };","affectsGlobalScope":true,"impliedNodeFormat":1},"282b6100cd3f6e9ff84f94bb8aee9402-export const value: number = \"error\";"],"options":{"composite":true},"semanticDiagnosticsPerFile":[[2,[{"pos":13,"end":18,"code":2322,"category":1,"messageKey":"Type_0_is_not_assignable_to_type_1_2322","messageArgs":["string","number"]}]]],"affectedFilesPendingEmit":[2],"emitSignatures":[2]}
//// [/home/src/workspaces/solution/project/tsconfig.tsbuildinfo.readable.baseline.txt] *new*
{
"version": "FakeTSVersion",
"root": [
{
"files": [
"./index.ts"
],
"original": 2
}
],
"fileNames": [
"lib.es2026.full.d.ts",
"./index.ts"
],
"fileInfos": [
{
"fileName": "lib.es2026.full.d.ts",
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"signature": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": "CommonJS",
"original": {
"version": "8859c12c614ce56ba9a18e58384a198f-/// <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> {}\ninterface SymbolConstructor {\n (desc?: string | number): symbol;\n for(name: string): symbol;\n readonly toStringTag: symbol;\n}\ndeclare var Symbol: SymbolConstructor;\ninterface Symbol {\n readonly [Symbol.toStringTag]: string;\n}\ndeclare const console: { log(msg: any): void; };",
"affectsGlobalScope": true,
"impliedNodeFormat": 1
}
},
{
"fileName": "./index.ts",
"version": "282b6100cd3f6e9ff84f94bb8aee9402-export const value: number = \"error\";",
"signature": "282b6100cd3f6e9ff84f94bb8aee9402-export const value: number = \"error\";",
"impliedNodeFormat": "CommonJS"
}
],
"options": {
"composite": true
},
"semanticDiagnosticsPerFile": [
[
"./index.ts",
[
{
"pos": 13,
"end": 18,
"code": 2322,
"category": 1,
"messageKey": "Type_0_is_not_assignable_to_type_1_2322",
"messageArgs": [
"string",
"number"
]
}
]
]
],
"affectedFilesPendingEmit": [
[
"./index.ts",
"Js|Dts",
2
]
],
"emitSignatures": [
{
"file": "./index.ts",
"original": 2
}
],
"size": 1199
}

project/tsconfig.json::
SemanticDiagnostics::
*refresh* /home/src/tslibs/TS/Lib/lib.es2026.full.d.ts
*refresh* /home/src/workspaces/solution/project/index.ts
Signatures::
Loading