Skip to content

Fix crash resolving ImportTypeNode in JSDoc #40838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12274,7 +12274,7 @@ namespace ts {
if (symbol.valueDeclaration) {
const isImportTypeWithQualifier = node.kind === SyntaxKind.ImportType && (node as ImportTypeNode).qualifier;
// valueType might not have a symbol, eg, {import('./b').STRING_LITERAL}
if (valueType.symbol && isImportTypeWithQualifier) {
if (valueType.symbol && valueType.symbol !== symbol && isImportTypeWithQualifier) {
typeType = getTypeReferenceType(node, valueType.symbol);
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/baselines/reference/jsdocImportTypeNodeNamespace.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
tests/cases/compiler/Main.js(2,14): error TS2352: Conversion of type 'string' to type 'typeof _default' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.


==== tests/cases/compiler/GeometryType.d.ts (0 errors) ====
// #40767

declare namespace _default {
export const POINT: string;
}
export default _default;

==== tests/cases/compiler/Main.js (1 errors) ====
export default function () {
return /** @type {import('./GeometryType.js').default} */ ('Point');
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2352: Conversion of type 'string' to type 'typeof _default' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.
}

18 changes: 18 additions & 0 deletions tests/baselines/reference/jsdocImportTypeNodeNamespace.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
=== tests/cases/compiler/GeometryType.d.ts ===
// #40767

declare namespace _default {
>_default : Symbol(_default, Decl(GeometryType.d.ts, 0, 0))

export const POINT: string;
>POINT : Symbol(POINT, Decl(GeometryType.d.ts, 3, 14))
}
export default _default;
>_default : Symbol(_default, Decl(GeometryType.d.ts, 0, 0))

=== tests/cases/compiler/Main.js ===
export default function () {
No type information for this code. return /** @type {import('./GeometryType.js').default} */ ('Point');
No type information for this code.}
No type information for this code.
No type information for this code.
19 changes: 19 additions & 0 deletions tests/baselines/reference/jsdocImportTypeNodeNamespace.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
=== tests/cases/compiler/GeometryType.d.ts ===
// #40767

declare namespace _default {
>_default : typeof _default

export const POINT: string;
>POINT : string
}
export default _default;
>_default : typeof _default

=== tests/cases/compiler/Main.js ===
export default function () {
return /** @type {import('./GeometryType.js').default} */ ('Point');
>('Point') : typeof import("tests/cases/compiler/GeometryType").default
>'Point' : "Point"
}

16 changes: 16 additions & 0 deletions tests/cases/compiler/jsdocImportTypeNodeNamespace.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true

// #40767

// @Filename: GeometryType.d.ts
declare namespace _default {
export const POINT: string;
}
export default _default;

// @Filename: Main.js
export default function () {
return /** @type {import('./GeometryType.js').default} */ ('Point');
}