XMLHTTPRequest的Angular 2打字问题

XMLHTTPRequest的Angular 2打字问题,angular,xmlhttprequest,typescript-typings,Angular,Xmlhttprequest,Typescript Typings,我正在使用XMLHttpRequest对象上载图像。我正在使用WebStorm作为编辑器。代码如下: uploadUserImage (files: File[], callback : any): void { let formData: FormData = new FormData(); let xhr = new XMLHttpRequest(); for (let i = 0; i < files.length; i++) {

我正在使用XMLHttpRequest对象上载图像。我正在使用WebStorm作为编辑器。代码如下:

    uploadUserImage (files: File[], callback : any): void {

    let formData: FormData = new FormData();

    let xhr = new XMLHttpRequest();

    for (let i = 0; i < files.length; i++) {
        formData.append("File", files[i], files[i].name);
    }

    xhr.open('POST', this._baseUrl + '/users/images', true);
    xhr.setRequestHeader('x-jwt-token', this._securityService.getJwt());
    xhr.onload = function(){
        callback(JSON.parse(this.responseText));
    };
    xhr.send(formData);
}
uploadUserImage(文件:File[],回调:any):无效{ 让formData:formData=newformdata(); 设xhr=newXMLHttpRequest(); for(设i=0;i 问题是在回调中我传递了这个.responseText。WebStorm正在将此对象标识为XMLHttpRequestEventTarget。当我尝试运行NPM Start时,我得到一个错误:

错误TS2339:类型“XMLHttpRequestEventTarget”上不存在属性“responseText”

我想我需要把它添加到打字中,但我不确定要添加什么。有什么想法吗

提前感谢您。

正在跟踪此信息。在修复之前,您可以使用

xhr.addEventListener('load', function() {
});
以消除类型错误

另一方面,如果使用angular,则不需要直接使用XMLHttpRequest。这是一个更好的选择