I encountered a situation where I have an object that returned the result from an RxJs subscribe method:
result: any
{
message: null
role: Object
success: true
}
To better manage this object in TypeScript, I decided to convert it to a type called MyResponse
:
export class BaseResponse {
public Message: string = null;
public Success: boolean = null;
}
export class MyResponse extends BaseResponse {
public Role: Role = new Role();
}
..
getModel() {
this.roleService.get(this.id).subscribe(
result => {
let getResponse: MyResponse = <MyResponse>result;
console.log(getResponse.Role.ApplicationId); // <-- null reference error
},
error => { },
() => {
}
);
}
An issue I noticed is that when inspecting the getResponse
object in Chrome debugger, its properties' names start with lowercase letters instead of uppercase. Is there a way to modify them to be capitalized?
getResponse
{
role: Object,
message: null,
success: true
}