Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate errors with noEmitOnError #543

Closed
demurgos opened this issue Oct 29, 2017 · 5 comments
Closed

Duplicate errors with noEmitOnError #543

demurgos opened this issue Oct 29, 2017 · 5 comments
Labels

Comments

@demurgos
Copy link
Contributor

demurgos commented Oct 29, 2017

When the option notEmitOnError is set to true, gulp-typescript reports all the errors twice. This is specific to gulp-typescript, there is no issue when passing this option to tsc.

The easiest way to understand it is to see an example (see below for the source code):

Actual behavior:

Unique errors are reported twice when using the option noEmitOnError.

$ gulp
[23:47:11] Using gulpfile /data/projects/various/duplicate-ts-gulp/gulpfile.js
[23:47:11] Starting 'default'...
src/index.ts(1,7): error TS2322: Type 'number' is not assignable to type 'string'.
src/index.ts(1,7): error TS2322: Type 'number' is not assignable to type 'string'.
[23:47:12] TypeScript: 1 semantic error
[23:47:12] TypeScript: 1 emit error
[23:47:12] TypeScript: emit failed
[23:47:12] Finished 'default' after 889 ms

Expected behavior:

Unique errors should only be reported once.

$ gulp
[23:47:11] Using gulpfile /data/projects/various/duplicate-ts-gulp/gulpfile.js
[23:47:11] Starting 'default'...
src/index.ts(1,7): error TS2322: Type 'number' is not assignable to type 'string'.
[23:47:12] TypeScript: 1 semantic error
[23:47:12] TypeScript: 1 emit error
[23:47:12] TypeScript: emit failed
[23:47:12] Finished 'default' after 889 ms

You can easily reproduce this error with the three following files (or just clone this temporary repo):

package.json

{
  "name": "duplicate-ts-gulp",
  "version": "1.0.0",
  "private": true,
  "devDependencies": {
    "gulp": "^3.9.1",
    "gulp-typescript": "^3.2.3",
    "typescript": "^2.5.3"
  }
}

gulpfile.js

var gulp = require('gulp');
var ts = require('gulp-typescript');

gulp.task('default', function () {
  return gulp.src('src/**/*.ts')
    .pipe(ts({noEmitOnError: true}))
    .pipe(gulp.dest('build'));
}); 

src/index.ts

const foo: string = 1 + 1;
@demurgos
Copy link
Contributor Author

demurgos commented Nov 5, 2017

The problem occurs here:

private emit(result: CompilationResult, callback: ts.WriteFileCallback) {
const emitOutput = this.program.emit(undefined, callback);
result.emitErrors += emitOutput.diagnostics.length;
this.reportDiagnostics(emitOutput.diagnostics);
result.emitSkipped = emitOutput.emitSkipped;
}

With {noEmitOnError: false}, I get the following output for emitOutput:

{ emitSkipped: false,
  diagnostics: [],
  emittedFiles: undefined,
  sourceMaps: undefined }

But with {noEmitOnError: true}, I get:

{ diagnostics: 
   [ { file: [Object],
       start: 6,
       length: 3,
       code: 2322,
       category: 1,
       messageText: 'Type \'1\' is not assignable to type \'string\'.' } ],
  sourceMaps: undefined,
  emittedFiles: undefined,
  emitSkipped: true }

demurgos added a commit to demurgos/gulp-typescript that referenced this issue Nov 6, 2017
@demurgos
Copy link
Contributor Author

demurgos commented Nov 6, 2017

I pushed a test-case demonstrating the issue on my branch issue-543. I added a test directory called noEmitOnError: this test is currently failing because of the duplicate emit.

A possible explanation is that the error seems to be counted both as a semantic error and emit error.

demurgos added a commit to demurgos/gulp-typescript that referenced this issue Nov 6, 2017
The uniqueness of the errors is checked by hashing them and adding
them to a set. If an error is already in the set, it is not reported.
To support older versions of Node, the set is implemented using
the keys of a JS object. The hash of diagnostic is created using a
JSON serializing of object (after dropping circular references).

Closes ivogabe#543
demurgos added a commit to demurgos/gulp-typescript that referenced this issue Nov 6, 2017
The uniqueness of the errors is checked by hashing them and adding
them to a set. If an error is already in the set, it is not reported.
To support older versions of Node, the set is implemented using
the keys of a JS object. The hash of diagnostic is created using a
JSON serializing of object (after dropping circular references).

Closes ivogabe#543
demurgos added a commit to demurgos/gulp-typescript that referenced this issue Nov 6, 2017
The uniqueness of the errors is checked by hashing them and adding
them to a set. If an error is already in the set, it is not reported.
To support older versions of Node, the set is implemented using
the keys of a JS object. The hash of diagnostic is created using a
JSON serializing of object (after dropping circular references).

Closes ivogabe#543
@ivogabe
Copy link
Owner

ivogabe commented Dec 23, 2017

Thanks for reporting and investigating this issue. I think this is an issue of TypeScript, I do not think that we should remove duplicate errors ourselves in gulp-typescript. So I reported microsoft/TypeScript#20876, and hope that we'll get a response from them soon.

@demurgos
Copy link
Contributor Author

The related TS issue was closed by this PR.

@demurgos
Copy link
Contributor Author

Thanks for fixing this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants