Skip to content

Commit f334476

Browse files
authored
Fix import type resolution in jsdoc, mark 2 (#35057)
Fake alias resolution only applies when the import type is followed by a qualified name. Otherwise the alias is sufficiently resolved already.
1 parent 94f8590 commit f334476

7 files changed

+103
-1
lines changed

src/compiler/checker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10852,7 +10852,8 @@ namespace ts {
1085210852
}
1085310853
isRequireAlias = isCallExpression(expr) && isRequireCall(expr, /*requireStringLiteralLikeArgument*/ true) && !!valueType.symbol;
1085410854
}
10855-
if (isRequireAlias || node.kind === SyntaxKind.ImportType) {
10855+
const isImportTypeWithQualifier = node.kind === SyntaxKind.ImportType && (node as ImportTypeNode).qualifier;
10856+
if (isRequireAlias || isImportTypeWithQualifier) {
1085610857
typeType = getTypeReferenceType(node, valueType.symbol);
1085710858
}
1085810859
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/jsdoc/ex.d.ts ===
2+
declare var config: {
3+
>config : Symbol(config, Decl(ex.d.ts, 0, 11))
4+
5+
fix: boolean
6+
>fix : Symbol(fix, Decl(ex.d.ts, 0, 21))
7+
}
8+
export = config;
9+
>config : Symbol(config, Decl(ex.d.ts, 0, 11))
10+
11+
=== tests/cases/conformance/jsdoc/test.js ===
12+
/** @param {import('./ex')} a */
13+
function demo(a) {
14+
>demo : Symbol(demo, Decl(test.js, 0, 0))
15+
>a : Symbol(a, Decl(test.js, 1, 14))
16+
17+
a.fix
18+
>a.fix : Symbol(fix, Decl(ex.d.ts, 0, 21))
19+
>a : Symbol(a, Decl(test.js, 1, 14))
20+
>fix : Symbol(fix, Decl(ex.d.ts, 0, 21))
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
=== tests/cases/conformance/jsdoc/ex.d.ts ===
2+
declare var config: {
3+
>config : { fix: boolean; }
4+
5+
fix: boolean
6+
>fix : boolean
7+
}
8+
export = config;
9+
>config : { fix: boolean; }
10+
11+
=== tests/cases/conformance/jsdoc/test.js ===
12+
/** @param {import('./ex')} a */
13+
function demo(a) {
14+
>demo : (a: { fix: boolean; }) => void
15+
>a : { fix: boolean; }
16+
17+
a.fix
18+
>a.fix : boolean
19+
>a : { fix: boolean; }
20+
>fix : boolean
21+
}
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/conformance/jsdoc/ex.d.ts ===
2+
export var config: {}
3+
>config : Symbol(config, Decl(ex.d.ts, 0, 10))
4+
5+
=== tests/cases/conformance/jsdoc/test.js ===
6+
/** @param {import('./ex')} a */
7+
function demo(a) {
8+
>demo : Symbol(demo, Decl(test.js, 0, 0))
9+
>a : Symbol(a, Decl(test.js, 1, 14))
10+
11+
a.config
12+
>a.config : Symbol(config, Decl(ex.d.ts, 0, 10))
13+
>a : Symbol(a, Decl(test.js, 1, 14))
14+
>config : Symbol(config, Decl(ex.d.ts, 0, 10))
15+
}
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
=== tests/cases/conformance/jsdoc/ex.d.ts ===
2+
export var config: {}
3+
>config : {}
4+
5+
=== tests/cases/conformance/jsdoc/test.js ===
6+
/** @param {import('./ex')} a */
7+
function demo(a) {
8+
>demo : (a: typeof import("tests/cases/conformance/jsdoc/ex")) => void
9+
>a : typeof import("tests/cases/conformance/jsdoc/ex")
10+
11+
a.config
12+
>a.config : {}
13+
>a : typeof import("tests/cases/conformance/jsdoc/ex")
14+
>config : {}
15+
}
16+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @Filename: ex.d.ts
5+
declare var config: {
6+
fix: boolean
7+
}
8+
export = config;
9+
10+
// @Filename: test.js
11+
/** @param {import('./ex')} a */
12+
function demo(a) {
13+
a.fix
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @Filename: ex.d.ts
5+
export var config: {}
6+
7+
// @Filename: test.js
8+
/** @param {import('./ex')} a */
9+
function demo(a) {
10+
a.config
11+
}

0 commit comments

Comments
 (0)