狼吞虎咽+;browserify&x2B;typescript-应为类型

狼吞虎咽+;browserify&x2B;typescript-应为类型,typescript,gulp,browserify,Typescript,Gulp,Browserify,我无法运行此脚本。每次它向我抛出一个错误: ->%gulp使用gulpfile~/wwwdata/projects/site/gulpfile.js[22:18:57]开始编译js[22:18:57] “编译js” events.js:141 投掷者;//未处理的“错误”事件 ^TS1110:app/Resources/src/tsc/Material.ts(22,19):TS1110:预期类型 第22行是这样的: private _xhr: null | JQueryXHR; 如果我把它改成

我无法运行此脚本。每次它向我抛出一个错误:

->%gulp使用gulpfile~/wwwdata/projects/site/gulpfile.js[22:18:57]开始编译js[22:18:57] “编译js”

events.js:141 投掷者;//未处理的“错误”事件 ^TS1110:app/Resources/src/tsc/Material.ts(22,19):TS1110:预期类型

第22行是这样的:

private _xhr: null | JQueryXHR;
如果我把它改成

private _xhr:any;
然后我得到:

TS1005:app/Resources/src/tsc/Material.ts(147,33):TS1005:“=”预期值

在该方法中,为
for
循环生成的:

/** load threads/comments for current loaded material */
getThreads() {

    /** if there is no more threads to load just exit the function */
    if(this.isMoreThreads == false) {
        return;
    }

    let url = Routing.generate('comments', {
        type: this.materialType,
        id: this.materialId,
        page: this.page
    });


    if (this._xhr) {
        this._xhr.abort();
    }

    this._xhr = $.ajax(url, {
        method: 'POST',
        beforeSend: () => {
        },
        success: (response) => {

            if(!(response.hasOwnProperty('threads'))) {
                this.isMoreThreads = false;
                $(document.getElementById('loadMoreThreads')).remove();
                return;
            }

            //for (let thread in response.threads) { // <- if change 'of' to 'in' then there is no error
            for (let thread of response.threads) {
                let thr = new MaterialThread(thread);
                this.addThread = thr;

                this._commentsContainer.append(thr.render());
            }
        },
        error: () => {
            let act = confirm('Error has occurred. Refresh page?');
            if (act === true) {
                window.location.reload();
            }
        },
        complete: () => {
            this._commentsContainer.find('#loading').fadeOut();
            this._xhr = null;
        }
    });
}

您必须将exclude添加到
tsconfig
文件中,以使此错误无效TS1110:app/Resources/src/tsc/typings/jquery.d.ts(1491,54):TS1110

var tsconfig = {
    target: "es5",
    module: "commonjs",
    declaration: false,
    noImplicitAny: false,
    removeComments: true,
    noLib: false,
    "exclude": [
        "node_modules",
        "typings"
    ]
};

正如我所知,null只允许与void一起使用,而未定义与pipe操作符一起使用。它们是兄弟类型,只能在声明和其他类似于您尝试执行的操作之间赋值。@Fals,好的,让我们将其更改为
any
。第二个错误呢?TS1005表示缺少某些内容,如果您能提供更多代码,我们可以帮助您找到问题。一个常见的错误是:当我们没有指定类型时,用赋值。在此之前/之后的某些属性出现错误。此外,如果仔细查看,出现错误的行将更改为(147,33),这是新问题。@Fals我已更新了我的问题arghh,现在我遇到了这个问题:>TS1153:“let”声明仅在目标为ECMAScript 6及更高版本时可用。@breq您应该将节点更新为最新版本,以及您的typescript版本,我在这里尝试了一些以let为目标的ES5代码,结果很好。我使用的是typescript v 2.2.2和节点v 4.2.6。这是我实际的gulpfile.js和tsconfig.json
var tsconfig = {
    target: "es5",
    module: "commonjs",
    declaration: false,
    noImplicitAny: false,
    removeComments: true,
    noLib: false,
    "exclude": [
        "node_modules",
        "typings"
    ]
};