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);
I am not sure if anyone can write here, but why would the satisfies operator have a need to nest? I thought it was supposed to be used for the declaration; That it is supposed to typecheck the expression to a constrain while preserving the original type;
satisfies
Operator#47920
#46827
instanceof
might do something similar here?That can lead to a "bad" contextual type occasionally.
Especially generic methods (e.g. array methods)
satisfies
?implements
?implements
again?extends
oninfer
in 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
Is
type 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
true
andfalse
, then widen toboolean
.boolean
because types of properties merge.boolean
inference from a return type, remove it from the instantiated contextual type, remove it.boolean
s - but doesn't work for other types. For example,const x: Box<0 | 1> = box(0)
.The text was updated successfully, but these errors were encountered: