I have defined the following types.
type Triple<A, B, C> = A & B & C;
type First<T> = T extends Triple<infer A, infer _B, infer _C> ? A : never;
type Second<T> = T extends Triple<infer _A, infer B, infer _C> ? B : never;
type Third<T> = T extends Triple<infer _A, infer _B, infer C> ? C : never;
// Scenario1: Expected behavior
type F1 = First<Triple<{ x: number }, { y: string }, { z: boolean }>>; // { x: number }
type S1 = Second<Triple<{ x: number }, { y: string }, { z: boolean }>>; // { y: string }
type T1 = Third<Triple<{ x: number }, { y: string }, { z: boolean }>>; // { z: boolean }
// Scenario2: Unexpected behavior
type XYZ = Triple<{ x: number }, { y: string }, { z: boolean }>;
type F2 = First<XYZ>; // unknown
type S2 = Second<XYZ>; // unknown
type T2 = Third<XYZ>; // unknown
Could someone clarify why the resulting types in Scenario2
are showing as unknown
?
View it in action on typescript playground.