Union to Intersection
introduction#
Implement the advanced util type UnionToIntersection<U>
For example
ts
View on GitHubts
start point#
tsTry/* _____________ Your Code Here _____________ */typeUnionToIntersection <U > = anyÂ/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <UnionToIntersection <'foo' | 42 | true>, 'foo' & 42 & true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <UnionToIntersection <(() => 'foo') | ((i : 42) => true)>, (() => 'foo') & ((i : 42) => true)>>,]
take the challengetsTry/* _____________ Your Code Here _____________ */typeUnionToIntersection <U > = anyÂ/* _____________ Test Cases _____________ */typecases = [Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <UnionToIntersection <'foo' | 42 | true>, 'foo' & 42 & true>>,Type 'false' does not satisfy the constraint 'true'.2344Type 'false' does not satisfy the constraint 'true'.Expect <Equal <UnionToIntersection <(() => 'foo') | ((i : 42) => true)>, (() => 'foo') & ((i : 42) => true)>>,]