UnionKnown<A, B>:(unknown extends A ? B : A) | (unknown extends B ? A : B)
perform a union between two types, making sure that if either is unknown, then it'll be treated as never.
why is this useful? because in typescript's unknown is a supertype of all types (similar to any), which means that something like T | unknown = unknown.
thus, in a scenario where such a behavior is not desired, you can use this utility type: UnionKnown<T, unknown> = T
perform a union between two types, making sure that if either is
unknown
, then it'll be treated asnever
.why is this useful? because in typescript's
unknown
is a supertype of all types (similar toany
), which means that something likeT | unknown = unknown
.thus, in a scenario where such a behavior is not desired, you can use this utility type:
UnionKnown<T, unknown> = T