Type Operators
Example:
typeNonNullable<T>=Exclude<T,null|undefined>
By the way you can do some crazy stuff.
typeJsonifiedObject<Textendsobject>={[KinkeyofT]: Jsonified<T[K]>};typeJsonified<T>=Textendsstring|number|boolean|null ? T
: Textendsundefined|Function ? undefined
: Textends{toJSON(): infer R} ? R
: Textendsobject ? JsonfifiedObject<T>
: "wat";"Recursive" Conditional Types
Start off with the way that await unboxes Promises to their wrapped type.
typeAwaited<T>=TextendsPromise<infer R> ? R : T;
Problem: await keeps unwrapping until it gets something that isn't then-able.
You kind of want this:
typeAwaited<T>=whileTextendsPromise<infer R> ? R : T;
or this:
typeAwaited<T>=TextendsPromise<infer R> ? Awaited<R> : T;
More awaited work
What about this?
typeAwaited<T>=Textends{then(onfulfilled: (value: infer U)=>any): any} ? U :
Textends{then(...args: any[]): any} ? never : TThen we modify the definition of Promise to something like this:
interfacePromise{then<TResult1,TResult2>(onFulfilled: (value: Awaited<T>)=>TResult1,onRejected: (err: any)=>TResult2):
Promise<Awaited<TResult1|TResult2>>}This almost works!
But there's a problem.
Because the type system doesn't know how to relate an arbitrary T to an Awaited<T> (and vice-versa).
Even if we had the "while types"/recursive conditional types, we'd have the same general problem unless we could think of a general way to handle this.
Resolve JSX namespaces from their factories
#18131
- What is the motivating scenario?
- Well there should be nothing preventing you from using multiple versions of React most of the time.
- But we have this problem with Node.
- But you only have one runtime environment; you can have multiple versions of React at runtime.
- [[Something about UMD]]
- What happens when you have multiple versions of UMD globals that come from different packages?
- Also, we want to make
JSX not global given the next issue... - Conclusion: Do this, fall back to a global JSX if nothing is available.
Decoupling JSX.Element from JSX expression return types.
#21699
- Also, using the JSX namespace is currently being used for too many things!
- JSX expressions don't always return the type specified by
JSX.Element.
- But people are now depending on this.
- Conclusion: Do this.
Per-file JSX emit
#21218
- Do we want a comment?
- It's the way Babel does it; why be different for no reason?
- Conclusion: do this.
Type Operators
Not crazy about giving these things names that people've been using.
Not crazy about
DiffIdeas
Diff->ExcludeFilter->Extractinjectetc. where I don't know what any of the methods actually do."ReturnTypesticks aroundInstanceTypeis the new "whatever this constructs"Example:
By the way you can do some crazy stuff.
"Recursive" Conditional Types
Start off with the way that
awaitunboxes Promises to their wrapped type.Problem:
awaitkeeps unwrapping until it gets something that isn'tthen-able.You kind of want this:
or this:
More awaited work
What about this?
Then we modify the definition of
Promiseto something like this:This almost works!
But there's a problem.
Because the type system doesn't know how to relate an arbitrary
Tto anAwaited<T>(and vice-versa).Even if we had the "
whiletypes"/recursive conditional types, we'd have the same general problem unless we could think of a general way to handle this.Resolve JSX namespaces from their factories
#18131
JSXnot global given the next issue...Decoupling
JSX.Elementfrom JSX expression return types.#21699
JSX.Element.Per-file JSX emit
#21218