How to change an object's class name?

Viewed 164

I would like to know, is there a way to:

  • change an object's class name? or
  • set class name to an anonymous class? or
  • dinamically generate the class name?

For example, I have a decorator:

export const decor = <T extends Constructable>(Clazz: T): T => {
    return class extends Clazz {
        constructor(...args: any[]) {
            super(...args);
            //...
        }
    };
};

It's a class decorator. All it does it's just add some extra logic to the object. But here's a problem. For the debugging I want to know the name of class. But if I use this decorator, the class name is look like class_1.

I tried to solve it with this attempts:

Dinamically generate the class name:

return class [`${Clazz.name}_dec`] extends Clazz // compilation error

Change an object's class name:

const tmp = class extends Clazz {...}
tmp.name = `${Clazz.name}_dec`; // this doesn't change anything
return tmp;

And none of them had worked.

So, is there a way to set class name in decorator or change it somehow?

0 Answers
Related