Skip to content

Instantly share code, notes, and snippets.

@rakeshta
Created February 14, 2025 00:26
Show Gist options
  • Save rakeshta/3463ad71f0343a084db46a71703d85fd to your computer and use it in GitHub Desktop.
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
/**
* 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