I am currently facing a dilemma with my two angular projects. The first one is a library while the second one is a regular Angular webapp. Within my library project, I have the following code snippet:
class User {
firstName: string;
lastName: string;
}
function instantiate<T extends Object>(constructor: new () => T) : T {
const obj = new constructor();
const keys = Object.keys(obj);
console.log('Object is:', obj);
console.log('Keys are:', keys);
return obj;
}
function testForStackOverflow() {
instantiate(User);
}
Output
Object is: User {firstName: undefined, lastName: undefined}
Keys are: (2) ['firstName', 'lastName']
The method above successfully creates a new User
object with empty fields, which is the intended behavior for the library project.
However, when I transfer this code to my webapp project, the output is different:
Object is: User {}
Keys are: (0) []
It seems that in the webapp project, the class is created with empty fields, resulting in an object without any properties. I have not made any configuration changes to cause this discrepancy in behavior.
Both projects were compiled using the latest versions of all packages, ruling out any versioning issues.