I encountered the following issue:
export class FloorManagerComponent implements OnInit
{
public meta = {
list: [],
building: Building,
loading: true,
};
constructor(
private router: Router,
private activatedRoute: ActivatedRoute,
private buildingService: BuildingService
)
{;}
public async ngOnInit()
{
let params = await this.activatedRoute.params.first().toPromise();
this.meta.building = await this.buildingService // line 42: ERROR
.getBuilding(params['buildingId']) // line 42: ERROR
.toPromise(); // line 42: ERROR
}
...
}
The error message I am receiving during compilation is as follows:
[at-loader] ./src/pages/floor/manager/floorManager.component.ts:42:9 TS2322: Type 'Building' is not assignable to type 'typeof Building'. Property 'prototype' is missing in type 'Building'.
I am currently stuck at this point - any insights?
Provided below are the details of the classes being utilized:
export class Building {
constructor(
public id: number,
public name: string,
public image_url: string,
) {}
...
}
export class BuildingService {
public getBuilding(buildingId: number)
{
return this.http.get(Url.api('buildings/' + buildingId))
.map( (response) => {
return Obj.cast(response, Building);
} );
}
...
}
export class Obj {
/**
* This method allows for casting json (and other types) objects to a specified type including methods
* CAUTION: The constructor of 'type' T is not called during casting
* Example usage:
*
* let space: Space = this.cast(spaceFromJson,Space);
*
* (we use type: { new(...args): T} to create fat arrow functions in prototpye... https://stackoverflow.com/a/32186367/860099)
*
* @param obj object (from json) with only fields and no methods
* @param type desired type
* @returns {any} object that has fields from obj and methods from type
*/
public static cast<T>(obj, type: { new(...args): T} ): T
{
obj.__proto__ = type.prototype;
return obj;
}
...
}