get all property names of a subclass in typescript?

Viewed 206

how could I get all property names of a subclass in typescript? I'm able to get all property names in the class, but it also gives me the ones in the base class, which I don't need.

base class

class BaseTestClass {
    public testVar: null = null;
}

sub class

class TestClass extends BaseTestClass {
    public longNameVar1: null = null;
    public longNameVar2: null = null;
    public longNameVar3: null = null;
    public longNameVar4: null = null;
    public longNameVar5: null = null;

}


let testClass = new TestClass()

let testClassProperties = Object.getOwnPropertyNames(testClass)
console.log(testClassProperties);
1 Answers

its because this how its done. if your print your testClass object, you could see is testVar is assigned in own property along with others. Nothing is inside __proto__

properties which goes in __proto__ are not considered as object own property

Related