-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Design Meeting Notes, 8/26/2016 #10566
Comments
@DanielRosenwasser Hey Dan, the CFA to track types, is that something that could get us closer to the error tracking that for instance Flow has, in the classic example:
Just wondering! Would be an amazing addition to TS if so 👍 |
Hey @MarkPieszak, that's a different thing actually. What's happening there is parameter type inference based on call-sites (note it doesn't work across modules). In general, it can be useful but it effectively makes such functions generic, which can impose a perf penalty. We've definitely considered it though. |
Yeah I imagine all those checks constantly running wouldn't be very performing especially in a large library. Good to know either way thanks for letting me know, always curious what's up and coming for TS, love 2.0+ you guys are killing it, nice work :) @DanielRosenwasser |
Regarding Object.assign and object spread/rest; please consider we also need to be able to type nested merges, not just shallow ones. rest params is handy for shallow merges, but is a pain for deep ones (e.g, this is an improvement, but doesn't remove the need for some kind of optional operator) |
The deep merge is already handled by intersection types today. declare function merge<T, U>(o1: T, o2: U): T & U;
merge({ prop: { a: 0 } }, { prop: { b: "string" } }); // equivalent to { prop: {a: number, b: string } } |
Sorry, wrong word. I meant, deep update without any type transformation for the output. |
that is the proposed declare function setState<T>(template: T, override: optionalize T): T;
setState({ prop: { a: 0 } }, { prop: { b: "string" } }); // Error {b:string} not assignable to {a:number} |
Expanded Inference (Open & Expando Style Types)
There's lots of code out there that has no type annotations at all, no initializers, starts out as an empty object.
That's mostly existing JavaScript code.
Anders has been working on using CFA to track types completely in certain situations.
This works pretty well if we have an accurate picture of the control flow graph; however, you can't model this that well if these variables are captured in another function.
For instance:
That means that 'any' has a much more limited scope of being implicitly introduced.
This makes Salsa way more powerful!
Expando Objects
Expando is a (somewhat documented) feature and pattern in JS where you can continue tacking properties on to objects after their creation.
In certain sites, we can decide that an object is meant to be created as an "expando" type.
For instance, how useful is the type
{}
on its own?The answer is "not very useful" (unless you're just using it for object identity), so we can build up the type as you assign properties to that object.
Every occurrence of
x
above has its own type.Q: Does this work for element access expressions?
A: No, haven't worked that far yet.
Q: Could we do this sort of thing for
this
in constructors?A: Potentially very bad experience - what happens if users set a value to
undefined
? It's worth experimenting with though.Q: Does this work for aliasing?
A: No, alias tracking would get pretty messy.
Expanded Array Element Inference
What about arrays?
This hasn't been implemented yet, but we have some ideas here.
Look for locations in which the array is added to (indexing,
push
,unshift
).Changes of Inference
General discussion about why an initializer is different from a deferred initialization.
Questions about inferring literal types, concerns about breaking changes.
tsconfig.json
InheritanceMerge or Overwrite?
Overwrite.
Multiple or Single Inheritance
Everyone: "SINGLE."
That was easy.
Object Literal Rest & Spread
Problem:
Object.assign
gives an intersection of its types.Easy to do when types aren't generic.
But what if they are?
Idea: new type operator like
{...T, ...U}
Q: What about if
U
has an optional property that exists inT
?A: Probably union the types of each property.
Enumerable & Own Properties
Problem is that
d
doesn't getmethod
because it's not enumerable or an own-property.We'd need a new modifier in type members.
"Optionalization"
There are often scenarios where you want to create a type with optional portions.
Not a lot of time to discuss this today.
The text was updated successfully, but these errors were encountered: