Yes, it’s generating DTOs, so you can do whatever you like with them. It’s best to leave DTO’s as data-only, otherwise you can’t ‘cast’ the result of a fetch to a DTO without instantiating each as an instance of that object type and injecting all the properties.
As a vanilla DTO you can cast the receive JSON data straight to the DTO type, as shown in the example above. The Project
is a DTO that was generated as an interface, and the line projects => this.accountProjects = projects
only works because the DTO is pure data without any metadata.
e.g.:
export interface Project {
Apikey?: string | undefined;
CustomerAccountId?: string | undefined;
Description?: string | undefined;
Name?: string | undefined;
ProjectId?: string | undefined;
ScriptVersion?: number | undefined;
TagsDefinition?: string | undefined;
}
I won’t post the whole of the promise
function, but the key aspect is this at the end:
projects(projectId: string, customerAccountId: string | undefined): Promise<Project[]> {
:
return this.http.fetch(url_, options_).then((_response: Response) => {
return <Project[]>JSON.parse(_responseText, this.jsonParseReviver);
});
}
Have fun