Recently, I started learning Angular and came across this snippet of code in my company's project:
currentCDFlow: CDCurrentFlowDTO;
this.currentCDFlow = await this.serivce.getCDMaster();
The code for getCDMaster() looks like this:
public async getCDMaster(): Promise<CDCurrentFlowDTO> {
return await this.http.post<CDCurrentFlowDTO>(Constants.BASE_HREF + '/getCDMaster', null, this.RequestJson).toPromise().catch(err => { throw err });
}
My question is, since getCDMaster() is returning a Promise<CDCurrentFlowDTO>
(a Promise object), how is it allowed to be assigned to an object of type CDCurrentFlowDTO directly? I would expect it to only be assignable to an object of type Promise<CDCurrentFlowDTO>
, not just CDCurrentFlowDTO
without being enclosed in a Promise<...>.
In Java, for example:
String a = new ArrayList<String>();
would result in a compile error...
Is this a feature specific to TypeScript?