some my solutions for type-challenges
Last active
May 18, 2022 00:53
-
-
Save enpitsuLin/30539766563938d7739ea94bb4b2cd03 to your computer and use it in GitHub Desktop.
Author
Author
//00730-hard-union-to-tuple
type StringToUnion<T extends string> = T extends `${infer F}${infer R}` ? F | StringToUnion<R> : never尾递归和模板字符串
Author
//02822-hard-split
type Split<S extends string, SEP extends string> = Equal<string, S> extends true
? string[]
: S extends `${infer F}${SEP}${infer R}`
? R extends ''
? [F]
: [F, ...Split<R, SEP>]
: S extends ''
? SEP extends ''
? []
: ['']
: [S]面向case穷举,好像也没看到更优雅的解法😂
Author
//00189-easy-awaited
type MyAwaited<X> = X extends Promise<infer T> ? T extends Promise<infer P> ? MyAwaited<T> : T : never
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
其实这里有个对象元组互相转换的问题需要研究下