Union to Intersection
#
introductionImplement the advanced util type UnionToIntersection<U>
For example
ts
type I = Union2Intersection<'foo' | 42 | true>; // expected to be 'foo' & 42 & true
View on GitHubts
type I = Union2Intersection<'foo' | 42 | true>; // expected to be 'foo' & 42 & true
#
start pointtsTry
/* _____________ 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)>>,]