0
在一個TypeScript快速入門中,有一部分將Object
投射到某個類。請參閱下面的完整代碼。TypeScript - 鑄造
.map(res => <RegisteredApplicationModel> res.json())
這是如何工作的?有沒有一些規範?在背景中發生的任何事情,還是僅僅是強制演員陣容,將所有領域的責任和正確的類型放在作者身上?
@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);
}