<WsIdSessionResponse>
doesn't make the object an instance of WsIdSessionResponse
. It cheats typing system to think that it is an instance and suppresses type errors. TypeScript is JavaScript with type safety, and it is just JavaScript when it's compiled.
Unless an instance of WsIdSessionResponse
is created explicitly with new
, the object will stay Object
, with no isOk
method.
The way it's supposed to work is:
interface IWsIdSessionResponse {
status: number;
username: string;
}
class WsIdSessionResponse implements IWsIdSessionResponse {
public status: number;
public username: string;
public isOk(): boolean {
return this.status == 1;
}
}
...
doLoginAsync(user: string, pwd: string): Promise<WsIdSessionResponse> {
...
return this.http.get<IWsIdSessionResponse>(this.apiUrl, {params: params})
.map(plainResponseObj => Object.assign(new WsIdSessionResponse, plainResponseObj))
.toPromise());
};