Skip to content

Commit cd9e5f8

Browse files
sheetalkamattypescript-bot
authored andcommitted
Fix incorrectly ignored dts file from project reference for resolution (#62438)
1 parent 0d9b9b9 commit cd9e5f8

File tree

3 files changed

+386
-2
lines changed

3 files changed

+386
-2
lines changed

src/compiler/program.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4083,10 +4083,9 @@ export function createProgram(_rootNamesOrOptions: readonly string[] | CreatePro
40834083
}
40844084
const getCommonSourceDirectory = memoize(() => getCommonSourceDirectoryOfConfig(resolvedRef.commandLine, !host.useCaseSensitiveFileNames()));
40854085
commandLine.fileNames.forEach(fileName => {
4086-
if (isDeclarationFileName(fileName)) return;
40874086
const path = toPath(fileName);
40884087
let outputDts;
4089-
if (!fileExtensionIs(fileName, Extension.Json)) {
4088+
if (!isDeclarationFileName(fileName) && !fileExtensionIs(fileName, Extension.Json)) {
40904089
if (!commandLine.options.outFile) {
40914090
outputDts = getOutputDeclarationFileName(fileName, resolvedRef.commandLine, !host.useCaseSensitiveFileNames(), getCommonSourceDirectory);
40924091
mapOutputFileToResolvedRef!.set(toPath(outputDts), { resolvedRef, source: fileName });

src/testRunner/unittests/tsbuild/moduleResolution.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,68 @@ describe("unittests:: tsbuild:: moduleResolution:: handles the modules and optio
9191
}),
9292
commandLineArgs: ["-b", "packages/pkg1.tsconfig.json", "packages/pkg2.tsconfig.json", "--verbose", "--traceResolution"],
9393
});
94+
95+
verifyTsc({
96+
scenario: "moduleResolution",
97+
subScenario: "resolution from d.ts of referenced project",
98+
sys: () =>
99+
TestServerHost.createWatchedSystem({
100+
"/home/src/workspaces/project/common.d.ts": "export type OnValue = (value: number) => void",
101+
"/home/src/workspaces/project/producer/index.ts": dedent`
102+
export { ValueProducerDeclaration } from "./in-js"
103+
import { OnValue } from "@common"
104+
export interface ValueProducerFromTs {
105+
onValue: OnValue;
106+
}
107+
`,
108+
"/home/src/workspaces/project/producer/in-js.d.ts": dedent`
109+
import { OnValue } from "@common"
110+
export interface ValueProducerDeclaration {
111+
onValue: OnValue;
112+
}
113+
`,
114+
"/home/src/workspaces/project/producer/tsconfig.json": jsonToReadableText({
115+
compilerOptions: {
116+
strict: true,
117+
composite: true,
118+
module: "nodenext",
119+
moduleResolution: "nodenext",
120+
paths: {
121+
"@common": ["../common.d.ts"],
122+
},
123+
libReplacement: false,
124+
},
125+
}),
126+
"/home/src/workspaces/project/consumer/index.ts": dedent`
127+
import { ValueProducerDeclaration, ValueProducerFromTs } from "@producer"
128+
declare let v: ValueProducerDeclaration;
129+
// n is implicitly any because onValue is actually any (despite what the tooltip says)
130+
v.onValue = (n) => {
131+
132+
}
133+
134+
// n is implicitly number as expected
135+
declare let v2: ValueProducerFromTs;
136+
v2.onValue = (n) => {
137+
138+
}`,
139+
"/home/src/workspaces/project/consumer/tsconfig.json": jsonToReadableText({
140+
compilerOptions: {
141+
strict: true,
142+
module: "nodenext",
143+
moduleResolution: "nodenext",
144+
paths: {
145+
"@producer": ["../producer/index"],
146+
},
147+
libReplacement: false,
148+
},
149+
references: [
150+
{ path: "../producer" },
151+
],
152+
}),
153+
}),
154+
commandLineArgs: ["--b", "consumer", "--traceResolution", "-v"],
155+
});
94156
});
95157

96158
describe("unittests:: tsbuild:: moduleResolution:: impliedNodeFormat differs between projects for shared file", () => {

0 commit comments

Comments
 (0)