Last active
September 4, 2019 08:17
-
-
Save imaximix/b203c1ba78f7b130b54ff1a42a036b81 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
interface MyCustomType<T> { | |
prop: Promise<T> | |
} | |
interface MyBlaBlaType { | |
prop: string | |
} | |
interface MyObj { | |
[key: string]: (...args: any) => any | |
} | |
function fn<M extends MyObj>(bla: M): { | |
[N in keyof M]: ReturnType<M[N]> extends MyCustomType<infer T> | |
? (...args: Parameters<M[N]>) => Promise<T> // I would like to tell TS that this will return Promise<what ever MyCustomType has as a generic ) | |
: M[N] | |
} { | |
// Implementation detail | |
return 123 as any; | |
} | |
// usage: | |
var y = fn({ | |
x1: | |
(): MyCustomType<string> => ({ prop: Promise.resolve("asd") }), | |
x2: | |
(): MyCustomType<number> => ({ prop: Promise.resolve(123) }), | |
x3: | |
(): MyBlaBlaType => ({ prop: "blabla" }) | |
}); // I would want to enforce y to be: { x1: Promise<string>, x2: Promise<number>, x3: MyBlaBlaType } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment