요약
"정적 필드 목록": Object.keys(classType)
"동적 필드 목록": Object.keys(new classType)
"정적 메소드 목록": Object.getOwnPropertyNames(classType).filter((v) => typeof (classType as any)[v] === "function")
"동적 메소드 목록": Object.getOwnPropertyNames(Object.getPrototypeOf(new classType)).filter((v) => v !== "constructor")
코드
class ExampleClass {
public field: number;
public static static_field: boolean;
public Method(){}
public static Static_Method(){}
}
type ClassType = { new(...args: any[]): any; };
function ClassTest(classType: ClassType) {
const classType: ClassType = ExampleClass;
// [ 'static_field' ]
Object.keys(classType)
// [ 'field' ]
Object.keys(new classType)
// [ ]
Object.keys(Object.getPrototypeOf(classType))
// [ ]
Object.keys(Object.getPrototypeOf(new classType))
// [ 'length', 'name', 'prototype', 'Static_Method', 'static_field' ]
Object.getOwnPropertyNames(classType)
// [ 'field' ]
Object.getOwnPropertyNames(new classType)
// [ 'length', 'name', 'arguments', 'caller', 'constructor', 'apply', 'bind', 'call', 'toString' ]
Object.getOwnPropertyNames(Object.getPrototypeOf(classType))
// [ 'constructor', 'Method' ]
Object.getOwnPropertyNames(Object.getPrototypeOf(new classType))
// [ 'Static_Method' ]
Object.getOwnPropertyNames(classType).filter((v) => typeof (classType as any)[v] === "function")
// [ 'Method' ]
Object.getOwnPropertyNames(Object.getPrototypeOf(new classType)).filter((v) => v !== "constructor")
}