class MyClass {
constructor() {}
aMethod() {}
anotherMethod() {}
aField = 'foo'
anotherField = 42
}
type MethodsMyClass = JustMethods<MyClass>
expectType<TypeEqual<MethodsMyClass, { aMethod: (arg: string) => string, anotherMethod: (num: number) => number }>>(true)
Original code from https://zirkelc.dev/posts/extract-class-methods
Note: Exclude<..., never> is used to force TypeScript to report final type as an object, not a type helper call
Extract the methods from a class, return a new structure with methods only.
Useful for extending & mocking methods only