Type Alias PropNames<T>

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

Extract the non-method key names from a class

Type Parameters

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

type PropNamesMyClass = PropNames<MyClass>
expectType<TypeEqual<PropNamesMyClass, 'aField' |'anotherField'>>(true)

constructor is not included