0

Give a type, a class for example

class User {
    Name: String;
    Surname: String;
    BirthDate: Date;

    constructor(
        name: String,
        surname: String,
        birthDate: Date) {
        this.Name = name;
        this.Surname = surname;
        this.BirthDate = birthDate;   
        }
}

how can I enumerate the type's properties names from the type, not from an instance of it?

The target result would an with the properties names (in any order):

['Name', 'Surname', 'BirthDate']
Sergio
  • 2,078
  • 3
  • 24
  • 41
  • 2
    @Pointy Your duplicate did not answer -> `from the type, not from an instance of it?` From what I can gather the answer is no, the accepted answer `just for fun` version is such a hack too.. – Keith Mar 23 '18 at 13:40
  • @Keith agreed, but that appeared to be a pretty good collection of options (and yes that hack is pretty bad). And you're right that the simple direct answer to this question is "No". Most of the answers there at least try to explain that it's not possible without an instance. – Pointy Mar 23 '18 at 13:42

0 Answers0