Last active
October 17, 2020 03:34
-
-
Save pveyes/12da7713a475394802e7743930759bf6 to your computer and use it in GitHub Desktop.
My solution for type challenge https://github.com/type-challenges/type-challenges
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 AppendArgument<Fn, A> = Fn extends (...args: infer Args) => infer R | |
? (...args: [...Args, A]) => R | |
: never |
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 TheActualCurry<T,R> = T extends [infer F, ...infer S] | |
? (...args: [F]) => TheActualCurry<S,R> | |
: R | |
declare function Currying<T extends readonly any[], R>(fn: (...args: [...T]) => R): TheActualCurry<T,R> |
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 DeepReadonly<T extends Record<string, any>> = { | |
readonly [k in keyof T]: T[k] extends number | boolean | string | Function | |
? T[k] | |
: DeepReadonly<T[k]> | |
} |
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 MyExclude<T, U> = T extends U ? never : T |
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 First<T extends any[]> = T[0] extends undefined ? never : T[0] |
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 If<C, T, F> = C extends boolean ? C extends true ? T : F : never |
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 Last<T extends any[]> = T extends [...infer _, infer L] ? L : never |
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 Length<T extends readonly any[]> = T["length"] |
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 WithType<T> = { | |
type: T | |
} | |
type LookUp<U, T> = U extends WithType<T> ? U : never |
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 MyOmit<T, K extends keyof T> = { | |
[k in Exclude<keyof T, K>]: T[k] | |
} |
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 MyPick<T, K extends keyof T> = { | |
[k in K]: T[k] | |
} |
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 Pop<T extends any[]> = T extends [...infer A, any] ? A : never |
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
// not finished, failed on case 3 | |
type ResolvePromise<T> = T extends Promise<infer U> ? U : T | |
type ResolvePromises<T> = { -readonly[P in keyof T]: ResolvePromise<T[P]> } | |
declare function PromiseAll<T extends readonly any[]>(values: T): Promise<ResolvePromises<T>> |
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 MyReadonly<T> = { | |
readonly [k in keyof T]: T[k] | |
} |
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 MyReturnType<T> = T extends (...args: any[]) => infer U ? U : any |
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 TupleToObject<T extends readonly any[]> = { | |
[k in T[number]]: k | |
} |
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 TupleToUnion<T extends readonly any[]> = T[number] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment