IntersectKnown<A, B>:(unknown extends A ? B : A) & (unknown extends B ? A : B)
perform an intersection between two types, making sure that if either is unknown or any, then it'll be ignored, and only the known type will persevere.
why is this useful? because in typescript's any is a subtype of all types, which means that something like T & any = any (strangely unintuitive).
thus, in a scenario where such a behavior is not desired, you can use this utility type: UnionKnown<T, any> = T
perform an intersection between two types, making sure that if either is
unknown
orany
, then it'll be ignored, and only the known type will persevere.why is this useful? because in typescript's
any
is a subtype of all types, which means that something likeT & any = any
(strangely unintuitive).thus, in a scenario where such a behavior is not desired, you can use this utility type:
UnionKnown<T, any> = T