This file contains hidden or 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 MyAwaited<T> = T extends PromiseLike<infer A> ? MyAwaited<A> : T; | |
| /* _____________ Test Cases _____________ */ | |
| import type { Equal, Expect } from '@type-challenges/utils' | |
| type X = Promise<string> | |
| type Y = Promise<{ field: number }> | |
| type Z = Promise<Promise<string | number>> | |
| type Z1 = Promise<Promise<Promise<string | boolean>>> | |
| type T = { then: (onfulfilled: (arg: number) => any) => any } |
This file contains hidden or 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
| /* _____________ Your Code Here _____________ */ | |
| type If<C extends boolean, T, F> = C extends true ? T: F | |
| /* _____________ Test Cases _____________ */ | |
| import type { Equal, Expect } from '@type-challenges/utils' | |
| type cases = [ | |
| Expect<Equal<If<true, 'a', 'b'>, 'a'>>, | |
| Expect<Equal<If<false, 'a', 2>, 2>>, |
This file contains hidden or 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 MyReadonly2<T, K extends keyof T = keyof T> = { | |
| readonly [P in K] :T[P] | |
| } & { | |
| [P in keyof T as P extends K ? never : P] : T[P] | |
| } |
This file contains hidden or 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 Concat<T extends readonly unknown[], U extends readonly unknown[]> = [...T, ...U] |
This file contains hidden or 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 Includes<T extends readonly any[], U> = | |
| T extends [infer First, ...infer Rest] | |
| ? ( | |
| Equal<First, U> extends true | |
| ? true | |
| : Includes<Rest, U> | |
| ) | |
| : false | |
| /* _____________ Test Cases _____________ */ |
This file contains hidden or 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 Push<T extends unknown[], U> = [...T, U] |
This file contains hidden or 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 Unshift<T extends unknown[], U> = [U, ...T] |
This file contains hidden or 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 MyParameters<T extends (...args: any[]) => any> = T extends (...any:infer S) => any ? S: any |
This file contains hidden or 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> = { | |
| [P in keyof T as P extends K ? never: P] :T[P] | |
| } |
This file contains hidden or 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> = { | |
| readonly [K in keyof T]: | |
| T[K] extends Function | |
| ? T[K] | |
| : T[K] extends { [K in string] : any} | |
| ? DeepReadonly<T[K]>: T[K] | |
| } |