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-27 19:54:43 -05:00
parent 41d1ce62cd
commit e65ce53dd8
4 changed files with 30 additions and 1 deletions
+2 -1
View File
@@ -10831,7 +10831,8 @@ namespace ts {
}
const isDelayedMergeClass = symbol !== valueType.symbol && getMergedSymbol(symbol) === valueType.symbol;
const isImportTypeWithQualifier = node.kind === SyntaxKind.ImportType && (node as ImportTypeNode).qualifier;
if (isRequireAlias || isImportTypeWithQualifier || isDelayedMergeClass) {
// valueType might not have a symbol, eg, {import('./b').STRING_LITERAL}
if (valueType.symbol && (isRequireAlias || isImportTypeWithQualifier || isDelayedMergeClass)) {
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;