Gulp + browserify + typescript - 预期类型

时间:2017-04-12 20:22:50

标签: typescript gulp browserify

我无法运行此脚本。每次它都会给我一个错误:

  

- > %gulp compile-js [22:18:57]使用gulpfile〜/ wwwdata / projects / site / gulpfile.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;
        }
    });
}

我的gulpfile.js

var tsconfig = {
    target: "es5",
    module: "commonjs",
    declaration: false,
    noImplicitAny: false,
    removeComments: true,
    noLib: false
};

gulp.task('compile-js', function() {
    var bundler = browserify({
        basedir: paths.typescript,
        debug: true,
    })
        .add(paths.typescript + '/index.ts')
        .plugin(tsify, tsconfig)
        .transform(debowerify);

    return bundler.bundle()
        .pipe(exorcist('/dupa/application.js.map'))
        .pipe(source('application.js'))
        .pipe(gulp.dest('/dupa'));
});

1 个答案:

答案 0 :(得分:0)

您必须在您的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"
    ]
};