Using Angular 5, I encountered an unusual problem with the class.name property. We have a TypeScript function as shown below:
export class ApiService
{
public list<T>(c: new(values: Object)=> T)
{
var cname = c.name;
....
}
}
When using this function in the development build of Angular (ng-build) with the Employee class like so:
export class Employee()
{
public id:string;
public name: string;
constructor(values: Object = {}) {
Object.assign(this, values);
}
}
And somewhere in the code:
var list = api.list(Employee);
It works fine and 'cname' is equal to 'Employee' in the list function.
However, when we build the solution using ng build --env=prod, the code fails and 'cname' becomes undefined.
What could be causing this issue and how can it be resolved? Shouldn't something that functions correctly in the development build also work in production?