Is there a standard method to parametrically define a union? I'm searching for a way to generically define something like:
type U<K> = T<K1> | T<K2> | ... | T<Kn> // Where K === (K1 | ... | Kn)
Note: I'm encountering a situation where
T<U | V> !== T<U> | T<V>
. (A bit opposite of #14107 and #16644)
Edit: When K
is a combination of string literals, I've noticed the following pattern:
type U<K> = {[key in K]: T<key>}[K]
However, it doesn't work well with type inference when used as a function argument.