Fixed a crash when computing flow type of destructured never (#57586)

This commit is contained in:
Mateusz Burzyński
2024-03-01 01:00:36 +01:00
committed by GitHub
parent e089896be4
commit af0424c010
5 changed files with 88 additions and 1 deletions

View File

@@ -43214,7 +43214,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
function getIteratedTypeOrElementType(use: IterationUse, inputType: Type, sentType: Type, errorNode: Node | undefined, checkAssignability: boolean): Type | undefined {
const allowAsyncIterables = (use & IterationUse.AllowsAsyncIterablesFlag) !== 0;
if (inputType === neverType) {
reportTypeNotIterableError(errorNode!, inputType, allowAsyncIterables); // TODO: GH#18217
if (errorNode) {
reportTypeNotIterableError(errorNode, inputType, allowAsyncIterables);
}
return undefined;
}

View File

@@ -0,0 +1,19 @@
autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts(9,3): error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
==== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts (1 errors) ====
// https://github.com/microsoft/TypeScript/issues/57582
declare const b: null;
let file;
if (b === null) {
// empty
} else {
[file] = b;
~~~~~~
!!! error TS2488: Type 'never' must have a '[Symbol.iterator]()' method that returns an iterator.
}
file; // request flow type here

View File

@@ -0,0 +1,24 @@
//// [tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts] ////
=== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts ===
// https://github.com/microsoft/TypeScript/issues/57582
declare const b: null;
>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13))
let file;
>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3))
if (b === null) {
>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13))
// empty
} else {
[file] = b;
>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3))
>b : Symbol(b, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 2, 13))
}
file; // request flow type here
>file : Symbol(file, Decl(autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts, 3, 3))

View File

@@ -0,0 +1,27 @@
//// [tests/cases/compiler/autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts] ////
=== autoTypeAssignedUsingDestructuringFromNeverNoCrash.ts ===
// https://github.com/microsoft/TypeScript/issues/57582
declare const b: null;
>b : null
let file;
>file : any
if (b === null) {
>b === null : boolean
>b : null
// empty
} else {
[file] = b;
>[file] = b : never
>[file] : [any]
>file : any
>b : never
}
file; // request flow type here
>file : any

View File

@@ -0,0 +1,15 @@
// @strict: true
// @noEmit: true
// https://github.com/microsoft/TypeScript/issues/57582
declare const b: null;
let file;
if (b === null) {
// empty
} else {
[file] = b;
}
file; // request flow type here