I keep encountering an error whenever I try to run this script. The error message I receive is:
-> % gulp compile-js [22:18:57] Using gulpfile ~/wwwdata/projects/site/gulpfile.js [22:18:57] Starting 'compile-js'...
events.js:141 throw er; // Unhandled 'error' event ^ TS1110: app/Resources/src/tsc/Material.ts(22,19): TS1110: Type expected.
The issue seems to be with line 22 of the script:
private _xhr: null | JQueryXHR;
When I change it to
private _xhr:any;
I encounter another error:
TS1005: app/Resources/src/tsc/Material.ts(147,33): TS1005: '=' expected.
This new error is triggered by the for
loop in the following method:
/** 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;
}
});
}
Here is the content of my 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'));
});