You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most recent change involves the contextual type of the expression being the intersection of the outer contextual type and the type being checked for satisfaction.
Have to be careful - there are places where we don't always create intersections because it's not always desirable to do this.
instanceof might do something similar here?
Intersections? For things with methods? That will produce overload methods?
That can lead to a "bad" contextual type occasionally.
Prioritized list - if you have a type variable bounded by number | bigint, first try to parse out number. If that isn't round-trippable, try to parse out bigint.
typeBox<T>={get: ()=>T;set: (x: T)=>void;};declarefunctionbox<T>(x: T): Box<T>;// okay, Box<number>consta=box(0);// okay, Box<number>, `0` gets contextually typed but doesn't make a difference.constb: Box<number>=box(0);// okay, Box<boolean>constc=box(false);// error!?// `false` gets contextually typed by `boolean` which is `true | false`// which makes the type of the extression `false` be the type `false`.// That means we try to see if the type `Box<false>` is assignable to `Box<boolean>`,// and it's not because `Box` is assignability is invariant on `T`.constd: Box<boolean>=box(false);
satisfiesOperator#47920
#46827
instanceofmight do something similar here?That can lead to a "bad" contextual type occasionally.
Especially generic methods (e.g. array methods)
satisfies?implements?implementsagain?extendsoninferin Conditional Types#48112
?after anextends SomeType, we always have to assume that we're about to start parsing a conditional type on the right.Inferring More Specific Types for Template Constraints
#48094
Istype Is<T extends U, U> = T, withIs<infer T, number>number | bigint, first try to parse outnumber. If that isn't round-trippable, try to parse outbigint.Contextually Typing Boolean Literals
#48363
#48380
trueandfalse, then widen toboolean.booleanbecause types of properties merge.booleaninference from a return type, remove it from the instantiated contextual type, remove it.booleans - but doesn't work for other types. For example,const x: Box<0 | 1> = box(0).