[英]TypeScript - casting
在一个TypeScript快速入门中,有一部分将Object
强制转换为某个类。 请参阅下面的完整代码。
.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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.