Control Flow Analysis for Array Construction (#11432)
AH: Improving furthur on un-annotated initializers, we have expanded our logic to "evolve" the type of an empty array.
functionf1(){letx=[];x;// never[]x[0]=5;x;// number[]x[1]="hello";x;// (number | string)[]}This evolution "stacks".
functionf1(){letx;x;// anyx=[];x;// never[]x[0]=5;x;// number[]x.push("hello");x;// (number | string)[]x=10;x// number}Junctions have interesting cases with constructions of exclusive types.
functionf1(){letx;if(/*...*/){x=[];x[0]=5;}else{x=[];x.push("hello");}returnx;}Subset Types (#11233)
Name is up for debate & bikeshedding.
interfaceState{name: string;length: number;foo?: number;}functionupdate(updates: subsetState){// ...}update({name: "bob"});// okayupdate({name: 100});// errorupdate({glorb: "florb"});// error: excess propertyfunctionsetState<T>(state: T,updates: subsetT){// ...}lets={a: 10,b: 20};setState(s,{a: 10});setState(s: {c: 100});// error: excess propertyProblem is that users excess property checking can be lost through intermediate assignments
Generics
What happens when you have a partial type parameter in a function?
functiondoSomething<T>(x: T){lety: subsetT;// (1) - okayy=x;// (2) - okayx=y;// (3) - Huh!?y={surprise: "this works!"};}Resolution: Only things that are assignable to subset T are
Tsubset Tany.
What about this?
functiondoSomething<Textends{foo: string}>(x: T){lety: subsetT=null;// (1) - ???y={foo: "hello"};}Resolution: Not allowed.
Why?
We can be more conservative later, but if you think about it from the perspective of no constraint (where it's implicitly {}), then really any type should be assignable to subset T in those scenarios.
Non-properties
Index Signatures
interfaceFoo{[x: string]: string;}// Effectively the same as '{ [x: string]: string | undefined }'.letqq: subsetFoo={};qq["blah"]="okay?";Name of
Resolution: subset
Extensibility (#10159)
More of a meta discussion.
Uses
- Templating systems that can work with the type system.
- Arbitrary buffers
- Allowing linting tools to hook into diagnostic reporting.
All are in some way related to language service.
Pros
Great tooling, allows different libraries & frameworks to give an augmented experience.
Cons
- Coordination can be complex, user experience is at risk.
- Need to provide way of diagnosing extensions & sandboxing.
- API surface area increases, must be maintained.
- Can't break extensions once they ship.
Status
Unresolved.
Control Flow Analysis for Array Construction (#11432)
AH: Improving furthur on un-annotated initializers, we have expanded our logic to "evolve" the type of an empty array.
This evolution "stacks".
Junctions have interesting cases with constructions of exclusive types.
Subset Types (#11233)
Name is up for debate & bikeshedding.
Problem is that users excess property checking can be lost through intermediate assignments
Generics
What happens when you have a partial type parameter in a function?
Resolution: Only things that are assignable to
subset TareTsubset Tany.What about this?
Resolution: Not allowed.
Why?
We can be more conservative later, but if you think about it from the perspective of no constraint (where it's implicitly
{}), then really any type should be assignable tosubset Tin those scenarios.Non-properties
Index Signatures
Name of
Resolution:
subsetExtensibility (#10159)
More of a meta discussion.
Uses
All are in some way related to language service.
Pros
Great tooling, allows different libraries & frameworks to give an augmented experience.
Cons
Status
Unresolved.