J
J
jershell2016-12-23 13:34:55
typescript
jershell, 2016-12-23 13:34:55

How to get the list and type of class properties?

There is a class

class MyClass {
    name: string;
    age: number;
}

And I wanted somewhere in the code:
getTypes(MyClass)
Is this possible through reflection ts?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-12-24
@jershell

After compilation, all types evaporate without a trace. You might like to use decorators like this:

class string {...}
class number {...}

class MyClass {
    @type(string)
    name: string;

    @type(number)
    age: number;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question