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
A new generic UnionToIntersection<> which converts from a union to an intersection
π Motivating Example
There are 20k views and 250 upvotes on a Stack Overflow question asking to convert from a union to an intersection.
The top rated answer? Check it out:
type UnionToIntersection<U> =
(U extends any ? (k: U)=>void : never) extends ((k: infer I)=>void) ? I : never
Nobody knows how it works, and it makes debugging a nightmare. But now there is a utility type for it!
(I guess this is how I could announce it on a blog post)
π» Use Cases
In my case, I'm chewing up massive amounts of resources and getting a The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed. message because of it.
I don't know what the other ~20k people felt who read that answer. Many were probably curious, but I'm sure many used it for other things.
The most basic example I can imagine is some function that takes an array of objects, then flattens them like so:
Suggestion
π Search Terms
Union to Intersection, Generic
https://stackoverflow.com/questions/50374908/transform-union-type-to-intersection-type
β Viability Checklist
My suggestion meets these guidelines:
β Suggestion
A new generic
UnionToIntersection<>
which converts from a union to an intersectionπ Motivating Example
There are 20k views and 250 upvotes on a Stack Overflow question asking to convert from a union to an intersection.
The top rated answer? Check it out:
Nobody knows how it works, and it makes debugging a nightmare. But now there is a utility type for it!
(I guess this is how I could announce it on a blog post)
π» Use Cases
In my case, I'm chewing up massive amounts of resources and getting a
The inferred type of this node exceeds the maximum length the compiler will serialize. An explicit type annotation is needed.
message because of it.I don't know what the other ~20k people felt who read that answer. Many were probably curious, but I'm sure many used it for other things.
The most basic example I can imagine is some function that takes an array of objects, then flattens them like so:
The text was updated successfully, but these errors were encountered: