Skip to content

Commit af0424c

Browse files
authored
Fixed a crash when computing flow type of destructured never (#57586)
1 parent e089896 commit af0424c

5 files changed

+88
-1
lines changed

src/compiler/checker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -43214,7 +43214,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4321443214
function getIteratedTypeOrElementType(use: IterationUse, inputType: Type, sentType: Type, errorNode: Node | undefined, checkAssignability: boolean): Type | undefined {
4321543215
const allowAsyncIterables = (use & IterationUse.AllowsAsyncIterablesFlag) !== 0;
4321643216
if (inputType === neverType) {
43217-
reportTypeNotIterableError(errorNode!, inputType, allowAsyncIterables); // TODO: GH#18217
43217+
if (errorNode) {
43218+
reportTypeNotIterableError(errorNode, inputType, allowAsyncIterables);
43219+
}
4321843220
return undefined;
4321943221
}
4322043222

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts(9,3): error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
2+
3+
4+
==== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts (1 errors) ====
5+
// https://github.com/microsoft/TypeScript/issues/57582
6+
7+
declare const b: null;
8+
let file;
9+
10+
if (b === null) {
11+
// empty
12+
} else {
13+
[file] = b;
14+
~~~~~~
15+
!!! error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
16+
}
17+
18+
file; // request flow type here
19+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//// [tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts] ////
2+
3+
=== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/57582
5+
6+
declare const b: null;
7+
>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13))
8+
9+
let file;
10+
>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3))
11+
12+
if (b === null) {
13+
>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13))
14+
15+
// empty
16+
} else {
17+
[file] = b;
18+
>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3))
19+
>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13))
20+
}
21+
22+
file; // request flow type here
23+
>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3))
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//// [tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts] ////
2+
3+
=== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts ===
4+
// https://github.com/microsoft/TypeScript/issues/57582
5+
6+
declare const b: null;
7+
>b : null
8+
9+
let file;
10+
>file : any
11+
12+
if (b === null) {
13+
>b === null : boolean
14+
>b : null
15+
16+
// empty
17+
} else {
18+
[file] = b;
19+
>[file] = b : never
20+
>[file] : [any]
21+
>file : any
22+
>b : never
23+
}
24+
25+
file; // request flow type here
26+
>file : any
27+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// @strict: true
2+
// @noEmit: true
3+
4+
// https://github.com/microsoft/TypeScript/issues/57582
5+
6+
declare const b: null;
7+
let file;
8+
9+
if (b === null) {
10+
// empty
11+
} else {
12+
[file] = b;
13+
}
14+
15+
file; // request flow type here

0 commit comments

Comments
 (0)