Skip to content

Commit efe6806

Browse files
committed
Fix getTypeFromJSDocValueReference
When using `{import('./b').FOO}` which is defined as a string literal, `valueType` doesn't have a `symbol`. This was exposed in 8223c07. Fixes #34869.
1 parent 0c17476 commit efe6806

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

src/compiler/checker.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -10840,7 +10840,8 @@ namespace ts {
1084010840
isRequireAlias = isCallExpression(expr) && isRequireCall(expr, /*requireStringLiteralLikeArgument*/ true) && !!valueType.symbol;
1084110841
}
1084210842
const isImportTypeWithQualifier = node.kind === SyntaxKind.ImportType && (node as ImportTypeNode).qualifier;
10843-
if (isRequireAlias || isImportTypeWithQualifier) {
10843+
// valueType might not have a symbol, eg, {import('./b').STRING_LITERAL}
10844+
if (valueType.symbol && (isRequireAlias || isImportTypeWithQualifier)) {
1084410845
typeType = getTypeReferenceType(node, valueType.symbol);
1084510846
}
1084610847
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/conformance/jsdoc/b.js ===
2+
export const FOO = "foo";
3+
>FOO : Symbol(FOO, Decl(b.js, 0, 12))
4+
5+
=== tests/cases/conformance/jsdoc/a.js ===
6+
/** @type {import('./b').FOO} */
7+
let x;
8+
>x : Symbol(x, Decl(a.js, 1, 3))
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
=== tests/cases/conformance/jsdoc/b.js ===
2+
export const FOO = "foo";
3+
>FOO : "foo"
4+
>"foo" : "foo"
5+
6+
=== tests/cases/conformance/jsdoc/a.js ===
7+
/** @type {import('./b').FOO} */
8+
let x;
9+
>x : "foo"
10+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @noEmit: true
2+
// @allowJs: true
3+
// @checkJs: true
4+
// @Filename: b.js
5+
export const FOO = "foo";
6+
7+
// @Filename: a.js
8+
/** @type {import('./b').FOO} */
9+
let x;

0 commit comments

Comments
 (0)