In einem TypeScript-Schnellstart gibt es einen Teil, der Object
in eine Klasse umwandelt. Siehe den vollständigen Code unten.TypeScript - Casting
.map(res => <RegisteredApplicationModel> res.json())
Wie funktioniert das? Gibt es dafür eine Spezifikation? Geschehen im Hintergrund oder zwingt es einfach die Besetzung, die Verantwortung, dass alle Felder gesetzt sind und vom richtigen Typ, auf den Autor dieser Zeile?
@Injectable()
export class RegisteredApplicationService {
private GET_APPLICATIONS_URL = "/registeredApplications/list";
private REGISTER_APPLICATION_URL = "/registeredApplications/register";
constructor (private _http: Http, private _constants: Constants) {}
registerApplication(application:RegisteredApplicationModel) {
let headers = new Headers();
let options = new RequestOptions({ headers: headers });
headers.append('Content-Type', 'application/json');
headers.append('Accept', 'application/json');
let body = JSON.stringify(application);
return this._http.put(this._constants.REST_BASE + this.REGISTER_APPLICATION_URL, body, options)
.map(res => <RegisteredApplicationModel> res.json())
.catch(this.handleError);
}