Created
February 14, 2025 00:26
-
-
Save rakeshta/3463ad71f0343a084db46a71703d85fd to your computer and use it in GitHub Desktop.
A utility type to extract all keys of a given type that are functions
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
/** | |
* A utility type to extract all keys of a given type that are functions. | |
* | |
* @example | |
* class Foo { | |
* static bar = 10; | |
* static baz() { | |
* return 'baz'; | |
* } | |
* } | |
* | |
* type FunctionOfFoo = FunctionsOf<typeof Foo>; // "baz" | |
*/ | |
export type FunctionsOf<T> = { | |
// eslint-disable-next-line @typescript-eslint/no-explicit-any | |
[K in keyof T]: T[K] extends (...args: any[]) => any ? K : never; | |
}[keyof T]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment