Last active
March 31, 2020 14:11
-
-
Save MeyCry/ac762fd128b8c090cc7d9acdb23f47e0 to your computer and use it in GitHub Desktop.
TypeScript Returned Value From Object Method By Key
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
/** | |
* example: | |
* const aObj = { | |
* b: () => 42, | |
* c: () => "hello" | |
* } | |
* type ObjExample = ReturnedValueFromObjectMethodByKey<typeof aObj>; | |
* ObjExample type will be: {b: number; c: string} | |
*/ | |
export type ReturnedValueFromObjectMethodByKey<T> = { | |
[K in keyof T]: T[K] extends (...args: any) => any ? ReturnType<T[K]> : T[K]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment