You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// your answers// is incorrect!// type UnionToTuple<T> = [T] extends [never] ? never : T extends undefined ? never : [T]/** * UnionToIntersection<{ foo: string } | { bar: string }> = * { foo: string } & { bar: string }. */typeUnionToIntersection<U>=(Uextendsunknown ? (arg: U)=>0 : never)extends(arg: infer I)=>0
? I
: never;/** * LastInUnion<1 | 2> = 2. * */typeLastInUnion<U>=UnionToIntersection<Uextendsunknown ? (x: U)=>0 : never>extends(x: infer L)=>0
? L
: never;/** * UnionToTuple<1 | 2> = [1, 2]. * see https://github.com/type-challenges/type-challenges/issues/737#issuecomment-791505468 */typeUnionToTuple<U,Last=LastInUnion<U>>=[U]extends[never]
? []
: [...UnionToTuple<Exclude<U,Last>>,Last];
typeh=((x: 1)=>0)&((x: 2)=>0)//why h not never
Function arguments are in contravariant positions, so when functions intersect, arguments do not intersect, but are united. This intersection of functions forms an overload -- a function that takes either 1 or 2 as its first argument.
typee=(((x: 1)=>0)&((x: 2)=>0))extends(x: infer L)=>0 ? L : never;// why e is 2 not never or 1?
This is a feature of TS, mentioned somewhere in the documentation -- if it is necessary to output one type from overload, TS selects the last signature ((x: 2) => 0) in the overload.
The text was updated successfully, but these errors were encountered:
The text was updated successfully, but these errors were encountered: