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:
Eli Barzilay
2019-11-25 18:12:45 -05:00
parent d6bd3ac552
commit d6740cf410
4 changed files with 30 additions and 1 deletions

View File

@@ -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);
}
}

View File

@@ -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))

View File

@@ -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"

View File

@@ -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;