This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* CheatSheet: A common pattern and its three states */ | |
// Left, Right, Exist | |
type L<T extends any[]> = T extends [infer L, ... infer R] ? L : T | |
type R<T extends any[]> = T extends [infer L, ... infer R] ? R : T | |
type E<T extends any[]> = T extends [infer L, ... infer R] ? true : false | |
// 1, [2], true | |
type L1 = L<[1, 2]> | |
type R1 = R<[1, 2]> | |
type E1 = E<[1, 2]> | |
// 1, [], true |