Repository navigation
Do not create JavaScript files on errors #828
Description
Activity
RyanCavanaugh commented
on Oct 6, 2014 MemberMore actionsWe 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.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').- addedSuggestionAn idea for TypeScriptAn idea for TypeScriptand removedBugA bug in TypeScriptA bug in TypeScript
on Oct 6, 2014 - assigned and unassigned
on Oct 6, 2014 - added this to the This milestone has been deleted milestone
on Oct 6, 2014 DickvdBrink commented
on Nov 17, 2014 ContributorMore actionsThis one is fixed and can be closed right?
- addedFixedA PR has been merged for this issueA PR has been merged for this issue
on Nov 17, 2014 RyanCavanaugh commented
on Nov 17, 2014 MemberMore actionsYep. Documenting that we merged this in with the name
noEmitOnErrorReacted by Igor Kriklivetc- locked and limited conversation to collaborators
on Jun 18, 2018
It seems that the TypeScript compiler still produces JavaScript output when the .ts files contains errors:
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).