Last active
September 16, 2018 06:51
-
-
Save gtkatakura/b9094a6ad9adabcb456fe27cd9138227 to your computer and use it in GitHub Desktop.
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
type TailArgs<T extends Function> = | |
T extends (head, ...tail: infer TTail) => any ? TTail : | |
unknown | |
type Tail<T extends Array<any>> = TailArgs<(...args: T) => any> | |
type YeahBaby = Tail<[1, 2, 3, 4]> // type YeahBaby = [2, 3, 4] |
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
type UnionToIntersection<U> = | |
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never | |
type ComponentType<T> = | |
T extends { props: infer TProps } ? TProps : | |
T | |
type AsProp<TComponents extends Array<any>> = UnionToIntersection<{ | |
[TComponent in keyof TComponents]: ComponentType<TComponents[TComponent]> | |
}[number]> | |
type ConditionalTypeAllTheThings = AsProp<[ | |
"div", | |
"xpto", | |
{ props: { value: "props" } } | |
]> // "div" & "xpto" & { value: "props" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment