jeudi 15 juillet 2021

How can I list all the get properties from a give object?

Give the class:

export class Foo
{
    #x: number;
    #y : number;

    constructor()
    {
        this.#x = 20;
        this.#y = 10;
    }

    public get a(): string { return "baa"; }
    public get n(): number { return 20; }
}

How can I get the getters properties i.e., ["a", "n"]? I have no code to show yet, I've looked reflect and reflect-metadata and I couldn't find anything to list those. I'm using typescript but javascript solutions are welcome too.





Aucun commentaire:

Enregistrer un commentaire