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

Do not create JavaScript files on errors #828

Closed
kersam-bl opened this issue Oct 6, 2014 · 4 comments
Closed

Do not create JavaScript files on errors #828

kersam-bl opened this issue Oct 6, 2014 · 4 comments
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript

Comments

@kersam-bl
Copy link

It seems that the TypeScript compiler still produces JavaScript output when the .ts files contains errors:

function testFunc(x: string) {
}
testFunc(1);

Compiling this file gives me an error message:
E:/tmp/typescripttest/Errors.ts(3,1): error TS2082: Supplied parameters do not match any signature of call target:
Could not apply type 'string' to argument 1 which is of type 'number'.
E:/tmp/typescripttest/Errors.ts(3,1): error TS2087: Could not select overload for 'call' expression.

But nevertheless a .js is created.

This seems odd to me. If a compiler reports an error, I do not expect it to create an output file and do as if the compilation would succeed. So the hint which tsc is giving me here is more of a type of a warning: There is something wrong, but the compiler still tries to continue.

Why is this important?
People tend to "ignore" the errors if they are not fatal.
Additionally, this heavily confuses our CI server, since the error just "disappears" on the next build (we do not recompile the tsc if they are older than the resulting JavaScript).

@mhegazy mhegazy added the Bug A bug in TypeScript label Oct 6, 2014
@RyanCavanaugh
Copy link
Member

We definitely want the behavior that the compiler can emit in the presence of type errors. This is a key scenario for migrating existing JavaScript -- you rename some .js file to .ts, get some type errors, but want to keep getting compilation of it while you refactor it to remove the type errors. They are 'warnings' in that sense; we cannot guarantee that your program does not work just because it has type errors.

That said, we recognize that this isn't always the behavior you want. Incremental builds get messed up by this on a fairly regular basis. We need something to address this scenario.

The most straightforward thing would be a command line flag (--doNotEmitOnErrors ? Could use a better name) that disables emit if we see type errors, same as how we don't emit if there are parse errors.

@danquirk
Copy link
Member

danquirk commented Oct 6, 2014

The compiler error code does now reflect the various possible outcomes of the compilation (ex EmitReturnStatus.JSGeneratedWithSemanticErrors) so it should be possible for tools like grunt-ts to give you some ability to configure your preferred behavior for cases like this (where what you want here is essentially 'warnings as errors').

@sophiajt sophiajt added Suggestion An idea for TypeScript and removed Bug A bug in TypeScript labels Oct 6, 2014
@sophiajt sophiajt assigned sophiajt and unassigned sophiajt Oct 6, 2014
@sophiajt sophiajt added this to the Community milestone Oct 6, 2014
@sophiajt sophiajt added the Help Wanted You can do this label Oct 6, 2014
@DickvdBrink
Copy link
Contributor

This one is fixed and can be closed right?

@RyanCavanaugh RyanCavanaugh added the Fixed A PR has been merged for this issue label Nov 17, 2014
@RyanCavanaugh
Copy link
Member

Yep. Documenting that we merged this in with the name noEmitOnError

@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Fixed A PR has been merged for this issue Help Wanted You can do this Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants