Access .constructor of class defined in TypeScript

typescript

Solution

This is rare enough in typed code that it's not included by default on the definition of `Object`. You can simply cast to `any` instead:

componentClass = (<any>component).constructor;

Problem

``` export class Entity { add(component: Component, componentClass?: { new (): Component;}): Entity { if (!componentClass) { componentClass = component.constructor } /** sniiiiip **/ } } ``` Line 4 of the example (assigning component.constructor) causes the compiler to complain that: The property 'constructor' does not exist on value of type 'Component' What's the proper way to get a reference to an objects constructor? My understanding is that all Objects in JavaScript have a .constructor property that points to the constructor used to create that object...

Original source