Some answers are partially wrong, and some facts in them are partially wrong as well.
Answer your question: Yes! You can.
In Typescript
class A {
private a1;
private a2;
}
Generates the following code in Javascript:
var A = /** @class */ (function () {
function A() {
}
return A;
}());
as @Erik_Cupal said, you could just do:
let a = new A();
let array = return Object.getOwnPropertyNames(a);
But this is incomplete. What happens if your class has a custom constructor? You need to do a trick with Typescript because it will not compile. You need to assign as any:
let className:any = A;
let a = new className();// the members will have value undefined
A general solution will be:
class A {
private a1;
private a2;
constructor(a1:number, a2:string){
this.a1 = a1;
this.a2 = a2;
}
}
class Describer{
describeClass( typeOfClass:any){
let a = new typeOfClass();
let array = Object.getOwnPropertyNames(a);
return array;//you can apply any filter here
}
}
For better understanding this will reference depending on the context.