Is it possible to get the interface name as a string?

Consider that I exported an interface

export interface IMyAngularService{
}

When we register a service or factory, we usually use the name of the function as the name of the registered service or just an output string (for example, "ISomeService" → "SomeService");

Later, I can decide to rename the interface and change the description of the dependencies automatically:

class MyController{

    static $inject = [
        dependency(nameof<ISomeService1>),
        dependency(nameof<ISomeService2>)
    ];

    constructor(...dependencies){
    }
}

where the dependencyfunction conditionally gets the service name from the interface name. Thus, whenever the name ISomeService1changes, the resulting JavaScript contains the changed strings.

+4
source share
1 answer

. TypeScript , nameof.

+9

All Articles