-
Notifications
You must be signed in to change notification settings - Fork 13k
Closed
Labels
DuplicateAn existing issue was already createdAn existing issue was already created
Description
TypeScript Version: Nightly
Search Terms: control flow analysis, reachability analysis, never, type annotation
Code
function impossible1(): never {
throw new Error();
}
const impossible2: () => never = () => {
throw new Error();
};
const impossible3 = (): never => {
throw new Error();
}
function foo(): never {
// impossible1 and impossible2 work here, but not impossible3
impossible3();
}
// but all seem to have the same type
const x: typeof impossible2 = impossible1;
const y: typeof impossible3 = impossible2;
const z: typeof impossible1 = impossible3;
Expected behavior:
The three functions with the same type should all behave the same under control flow/reachability analysis.
Actual behavior:
Using impossible3
, which removes the type annotation from the LHS, does not compile, while using impossible1
or impossible2
does.
Playground Link: Playground Link
Related Issues: N/A
Other issues exist related to reachability not working as expected, but removing the type annotation like this is a strange way to run into it.
nicod-pc and omril1acutmore and ivanhofer
Metadata
Metadata
Assignees
Labels
DuplicateAn existing issue was already createdAn existing issue was already created