Bug Report
🔎 Search Terms
type guard / fall through / narrow / change / lazy / evaluate
🕗 Version & Regression Information
- This changed between versions v4.7.4 and v4.8.2
⏯ Playground Link
Playground link with relevant code
💻 Code
typeIdentity<T>={[KinkeyofT]: T[K]};typeSelf<T>=Textendsunknown ? Identity<T> : never;functionis<T>(value: T): value is Self<T>{returntrue;}typeUnion={a: number}|{b: number}|{c: number};functionexample(x: Union){if(is(x)){}if(is(x)){}if(is(x)){}if(is(x)){}if(is(x)){}if(is(x)){}if(is(x)){}if(is(x)){}returnx;// ^?}🙁 Actual behavior
The type of x is "narrowed" to Identity<Identity<Identity<Identity<Identity<Identity<Identity<Identity<{a: number;}>>>>>>>> | Identity<Identity<Identity<Identity<Identity<Identity<Identity<Identity<{b: number;}>>>>>>>> | Identity<Identity<Identity<Identity<Identity<Identity<Identity<Identity<{c: number;}>>>>>>>>
It's as if a variable gets narrowed to the union of the types of both sides of the type predicate, e.g.
if(isA(aOrB)){// `aOrB` gets narrowed to `A`}else{// `aOrB` gets narrowed to `Exclude<typeof aOrB, A>`}// `aOrB` gets narrowed to `A | Exclude<typeof aOrB, A>` but it should just be left alone🙂 Expected behavior
The type of x doesn't change.
Bug Report
🔎 Search Terms
type guard / fall through / narrow / change / lazy / evaluate
🕗 Version & Regression Information
⏯ Playground Link
Playground link with relevant code
💻 Code
🙁 Actual behavior
The type of
xis "narrowed" toIdentity<Identity<Identity<Identity<Identity<Identity<Identity<Identity<{a: number;}>>>>>>>> | Identity<Identity<Identity<Identity<Identity<Identity<Identity<Identity<{b: number;}>>>>>>>> | Identity<Identity<Identity<Identity<Identity<Identity<Identity<Identity<{c: number;}>>>>>>>>It's as if a variable gets narrowed to the union of the types of both sides of the type predicate, e.g.
🙂 Expected behavior
The type of
xdoesn't change.