Skip to content

Design Meeting Notes, 10/10/2016 #11505

Description

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 property

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?

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

  1. T
  2. subset T
  3. any.

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

  1. Templating systems that can work with the type system.
  2. Arbitrary buffers
  3. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Design NotesNotes from our design meetings

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions