mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-19 10:41:56 -05:00
Fix getTypeFromJSDocValueReference
When using `{import('./b').FOO}` which is defined as a string literal,
`valueType` doesn't have a `symbol`. Leave it for the fallback value
for now.
This was exposed in 8223c0752.
Fixes #34869.
This commit is contained in:
@@ -10840,7 +10840,8 @@ namespace ts {
|
||||
isRequireAlias = isCallExpression(expr) && isRequireCall(expr, /*requireStringLiteralLikeArgument*/ true) && !!valueType.symbol;
|
||||
}
|
||||
const isImportTypeWithQualifier = node.kind === SyntaxKind.ImportType && (node as ImportTypeNode).qualifier;
|
||||
if (isRequireAlias || isImportTypeWithQualifier) {
|
||||
// valueType might not have a symbol, eg, {import('./b').STRING_LITERAL}
|
||||
if (valueType.symbol && (isRequireAlias || isImportTypeWithQualifier)) {
|
||||
typeType = getTypeReferenceType(node, valueType.symbol);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
=== tests/cases/conformance/jsdoc/b.js ===
|
||||
export const FOO = "foo";
|
||||
>FOO : Symbol(FOO, Decl(b.js, 0, 12))
|
||||
|
||||
=== tests/cases/conformance/jsdoc/a.js ===
|
||||
/** @type {import('./b').FOO} */
|
||||
let x;
|
||||
>x : Symbol(x, Decl(a.js, 1, 3))
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
=== tests/cases/conformance/jsdoc/b.js ===
|
||||
export const FOO = "foo";
|
||||
>FOO : "foo"
|
||||
>"foo" : "foo"
|
||||
|
||||
=== tests/cases/conformance/jsdoc/a.js ===
|
||||
/** @type {import('./b').FOO} */
|
||||
let x;
|
||||
>x : "foo"
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
// @noEmit: true
|
||||
// @allowJs: true
|
||||
// @checkJs: true
|
||||
// @Filename: b.js
|
||||
export const FOO = "foo";
|
||||
|
||||
// @Filename: a.js
|
||||
/** @type {import('./b').FOO} */
|
||||
let x;
|
||||
Reference in New Issue
Block a user