Skip to content

Commit 54f8062

Browse files
andrewbranchsnovader
authored andcommitted
Avoid unnecessary resolution-mode assertion in declaration emit (microsoft#55727)
1 parent 75ee6d2 commit 54f8062

5 files changed

+106
-2
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47760,11 +47760,14 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4776047760
function addReferencedFilesToTypeDirective(file: SourceFile, key: string, mode: ResolutionMode) {
4776147761
if (fileToDirective.has(file.path)) return;
4776247762
fileToDirective.set(file.path, [key, mode]);
47763-
for (const { fileName, resolutionMode } of file.referencedFiles) {
47763+
for (const { fileName } of file.referencedFiles) {
4776447764
const resolvedFile = resolveTripleslashReference(fileName, file.fileName);
4776547765
const referencedFile = host.getSourceFile(resolvedFile);
4776647766
if (referencedFile) {
47767-
addReferencedFilesToTypeDirective(referencedFile, key, resolutionMode || file.impliedNodeFormat);
47767+
// The resolution mode of the file reference doesn't actually matter here -
47768+
// all we're recording is the fact that the file entered the compilation
47769+
// transitively via a type reference directive of {key} with mode {mode}.
47770+
addReferencedFilesToTypeDirective(referencedFile, key, mode || file.impliedNodeFormat);
4776847771
}
4776947772
}
4777047773
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//// [tests/cases/compiler/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.ts] ////
2+
3+
//// [package.json]
4+
{
5+
"name": "@types/node",
6+
"version": "1.0.0",
7+
"types": "index.d.ts"
8+
}
9+
10+
//// [globals.d.ts]
11+
declare namespace NodeJS {
12+
interface ReadableStream {}
13+
}
14+
15+
//// [index.d.ts]
16+
/// <reference path="globals.d.ts" />
17+
18+
//// [app.mts]
19+
/// <reference types="node" />
20+
export async function drainStream(stream: NodeJS.ReadableStream): Promise<void> {
21+
}
22+
23+
24+
25+
26+
//// [app.d.mts]
27+
/// <reference types="node" />
28+
export declare function drainStream(stream: NodeJS.ReadableStream): Promise<void>;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.ts] ////
2+
3+
=== /app.mts ===
4+
/// <reference types="node" />
5+
export async function drainStream(stream: NodeJS.ReadableStream): Promise<void> {
6+
>drainStream : Symbol(drainStream, Decl(app.mts, 0, 0))
7+
>stream : Symbol(stream, Decl(app.mts, 1, 34))
8+
>NodeJS : Symbol(NodeJS, Decl(globals.d.ts, 0, 0))
9+
>ReadableStream : Symbol(NodeJS.ReadableStream, Decl(globals.d.ts, 0, 26))
10+
>Promise : Symbol(Promise, Decl(lib.es5.d.ts, --, --), Decl(lib.es2015.iterable.d.ts, --, --), Decl(lib.es2015.promise.d.ts, --, --), Decl(lib.es2015.symbol.wellknown.d.ts, --, --), Decl(lib.es2018.promise.d.ts, --, --))
11+
}
12+
13+
=== /node_modules/@types/node/globals.d.ts ===
14+
declare namespace NodeJS {
15+
>NodeJS : Symbol(NodeJS, Decl(globals.d.ts, 0, 0))
16+
17+
interface ReadableStream {}
18+
>ReadableStream : Symbol(ReadableStream, Decl(globals.d.ts, 0, 26))
19+
}
20+
21+
=== /node_modules/@types/node/index.d.ts ===
22+
23+
/// <reference path="globals.d.ts" />
24+
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//// [tests/cases/compiler/dtsEmitTripleSlashAvoidUnnecessaryResolutionMode.ts] ////
2+
3+
=== /app.mts ===
4+
/// <reference types="node" />
5+
export async function drainStream(stream: NodeJS.ReadableStream): Promise<void> {
6+
>drainStream : (stream: NodeJS.ReadableStream) => Promise<void>
7+
>stream : NodeJS.ReadableStream
8+
>NodeJS : any
9+
}
10+
11+
=== /node_modules/@types/node/globals.d.ts ===
12+
13+
declare namespace NodeJS {
14+
interface ReadableStream {}
15+
}
16+
17+
=== /node_modules/@types/node/index.d.ts ===
18+
19+
/// <reference path="globals.d.ts" />
20+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// @Filename: /tsconfig.json
2+
{
3+
"compilerOptions": {
4+
"module": "nodenext",
5+
"types": [],
6+
"declaration": true,
7+
"emitDeclarationOnly": true,
8+
}
9+
}
10+
11+
// @Filename: /node_modules/@types/node/package.json
12+
{
13+
"name": "@types/node",
14+
"version": "1.0.0",
15+
"types": "index.d.ts"
16+
}
17+
18+
// @Filename: /node_modules/@types/node/globals.d.ts
19+
declare namespace NodeJS {
20+
interface ReadableStream {}
21+
}
22+
23+
// @Filename: /node_modules/@types/node/index.d.ts
24+
/// <reference path="globals.d.ts" />
25+
26+
// @Filename: /app.mts
27+
/// <reference types="node" />
28+
export async function drainStream(stream: NodeJS.ReadableStream): Promise<void> {
29+
}

0 commit comments

Comments
 (0)