Skip to content

Commit a09a714

Browse files
authored
Fix crash resolving ImportTypeNode in JSDoc (microsoft#40838)
1 parent 05be3b4 commit a09a714

File tree

5 files changed

+72
-1
lines changed

5 files changed

+72
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12310,7 +12310,7 @@ namespace ts {
1231012310
if (symbol.valueDeclaration) {
1231112311
const isImportTypeWithQualifier = node.kind === SyntaxKind.ImportType && (node as ImportTypeNode).qualifier;
1231212312
// valueType might not have a symbol, eg, {import('./b').STRING_LITERAL}
12313-
if (valueType.symbol && isImportTypeWithQualifier) {
12313+
if (valueType.symbol && valueType.symbol !== symbol && isImportTypeWithQualifier) {
1231412314
typeType = getTypeReferenceType(node, valueType.symbol);
1231512315
}
1231612316
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
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.
2+
3+
4+
==== tests/cases/compiler/GeometryType.d.ts (0 errors) ====
5+
// #40767
6+
7+
declare namespace _default {
8+
export const POINT: string;
9+
}
10+
export default _default;
11+
12+
==== tests/cases/compiler/Main.js (1 errors) ====
13+
export default function () {
14+
return /** @type {import('./GeometryType.js').default} */ ('Point');
15+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
16+
!!! 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.
17+
}
18+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
=== tests/cases/compiler/GeometryType.d.ts ===
2+
// #40767
3+
4+
declare namespace _default {
5+
>_default : Symbol(_default, Decl(GeometryType.d.ts, 0, 0))
6+
7+
export const POINT: string;
8+
>POINT : Symbol(POINT, Decl(GeometryType.d.ts, 3, 14))
9+
}
10+
export default _default;
11+
>_default : Symbol(_default, Decl(GeometryType.d.ts, 0, 0))
12+
13+
=== tests/cases/compiler/Main.js ===
14+
export default function () {
15+
No type information for this code. return /** @type {import('./GeometryType.js').default} */ ('Point');
16+
No type information for this code.}
17+
No type information for this code.
18+
No type information for this code.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
=== tests/cases/compiler/GeometryType.d.ts ===
2+
// #40767
3+
4+
declare namespace _default {
5+
>_default : typeof _default
6+
7+
export const POINT: string;
8+
>POINT : string
9+
}
10+
export default _default;
11+
>_default : typeof _default
12+
13+
=== tests/cases/compiler/Main.js ===
14+
export default function () {
15+
return /** @type {import('./GeometryType.js').default} */ ('Point');
16+
>('Point') : typeof import("tests/cases/compiler/GeometryType").default
17+
>'Point' : "Point"
18+
}
19+
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
5+
// #40767
6+
7+
// @Filename: GeometryType.d.ts
8+
declare namespace _default {
9+
export const POINT: string;
10+
}
11+
export default _default;
12+
13+
// @Filename: Main.js
14+
export default function () {
15+
return /** @type {import('./GeometryType.js').default} */ ('Point');
16+
}

0 commit comments

Comments
 (0)