Skip to content

Commit c1128d6

Browse files
authored
Fix declaration emitted crash on mapped type with no type (#22213)
1 parent dafa732 commit c1128d6

File tree

6 files changed

+48
-1
lines changed

6 files changed

+48
-1
lines changed

src/compiler/declarationEmitter.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,12 @@ namespace ts {
608608
"?");
609609
}
610610
write(": ");
611-
emitType(node.type);
611+
if (node.type) {
612+
emitType(node.type);
613+
}
614+
else {
615+
write("any");
616+
}
612617
write(";");
613618
writeLine();
614619
decreaseIndent();
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests/cases/compiler/mappedTypeNoTypeNoCrash.ts(1,51): error TS2304: Cannot find name 'K'.
2+
tests/cases/compiler/mappedTypeNoTypeNoCrash.ts(1,51): error TS4081: Exported type alias 'T0' has or is using private name 'K'.
3+
tests/cases/compiler/mappedTypeNoTypeNoCrash.ts(1,57): error TS2304: Cannot find name 'K'.
4+
tests/cases/compiler/mappedTypeNoTypeNoCrash.ts(1,57): error TS4081: Exported type alias 'T0' has or is using private name 'K'.
5+
6+
7+
==== tests/cases/compiler/mappedTypeNoTypeNoCrash.ts (4 errors) ====
8+
type T0<T> = ({[K in keyof T]}) extends ({[key in K]: T[K]}) ? number : never;
9+
~
10+
!!! error TS2304: Cannot find name 'K'.
11+
~
12+
!!! error TS4081: Exported type alias 'T0' has or is using private name 'K'.
13+
~
14+
!!! error TS2304: Cannot find name 'K'.
15+
~
16+
!!! error TS4081: Exported type alias 'T0' has or is using private name 'K'.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
//// [mappedTypeNoTypeNoCrash.ts]
2+
type T0<T> = ({[K in keyof T]}) extends ({[key in K]: T[K]}) ? number : never;
3+
4+
//// [mappedTypeNoTypeNoCrash.js]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
=== tests/cases/compiler/mappedTypeNoTypeNoCrash.ts ===
2+
type T0<T> = ({[K in keyof T]}) extends ({[key in K]: T[K]}) ? number : never;
3+
>T0 : Symbol(T0, Decl(mappedTypeNoTypeNoCrash.ts, 0, 0))
4+
>T : Symbol(T, Decl(mappedTypeNoTypeNoCrash.ts, 0, 8))
5+
>K : Symbol(K, Decl(mappedTypeNoTypeNoCrash.ts, 0, 16))
6+
>T : Symbol(T, Decl(mappedTypeNoTypeNoCrash.ts, 0, 8))
7+
>key : Symbol(key, Decl(mappedTypeNoTypeNoCrash.ts, 0, 43))
8+
>T : Symbol(T, Decl(mappedTypeNoTypeNoCrash.ts, 0, 8))
9+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
=== tests/cases/compiler/mappedTypeNoTypeNoCrash.ts ===
2+
type T0<T> = ({[K in keyof T]}) extends ({[key in K]: T[K]}) ? number : never;
3+
>T0 : number
4+
>T : T
5+
>K : K
6+
>T : T
7+
>key : key
8+
>K : No type information available!
9+
>T : T
10+
>K : No type information available!
11+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// @declaration: true
2+
type T0<T> = ({[K in keyof T]}) extends ({[key in K]: T[K]}) ? number : never;

0 commit comments

Comments
 (0)