Type Alias MethodNames<T>

MethodNames<T>: {
    [K in keyof T]: T[K] extends ((...args: any[]) => any)
        ? K
        : never
}[keyof T]

Extract the method key names from a class

Type Parameters

  • T
class MyClass {
constructor() {}
aMethod() {}
anotherMethod() {}
aField = 'foo'
anotherField = 42
}

type MethodNamesMyClass = MethodNames<MyClass>
expectType<TypeEqual<MethodNamesMyClass, 'aMethod' |'anotherMethod'>>(true)

constructor is not included