Errors that you would expect to get by running the typescript compiler are not being reported by the transformer
Closed this issue · 6 comments
Basically, if you write something like this in typescript:
switch (x) {
case 1:
console.log('y');
case 2:
console.log(x);
}
And put:
"noFallthroughCasesInSwitch": true,
in your tsconfig.json, then if you compile w/ typescript (e.g. tsc
) you'll get an error. Thats good!
BUT, with the transformer, the typescript is transpiled successfully, and you don't get an error.
There seems to be a whole slew of little nice errors you get normally with the typescript compiler, that the transformer isn't reporting.
I believe its probably because the transpileModule
function you are using does not do the full analysis that the normal complication pass does.
This seems relevant:
microsoft/TypeScript#4864
Do you have any idea how we could fix this?
Thanks!
Aaron
That is the desired behaviour. i.e. the transformer should only report syntax errors which prevent emitting code. All other errors should be displayed/reported by external tooling like code highlighting and a precommit hook that runs tsc --noEmit
.
Otherwise you couldn't run type-unsafe code a dev time. Which might sound like an insane desire to some people, "why would you ever want to run unsafe code", but is actually a very productive feature because it lets you experiment and make incremental changes with less overhead.
Thanks for your response. I have been thinking about this for a few days... I admit it does feel a little foreign to me, but what you are saying is reasonable and I think I am coming over to your point of view. :)
We are also going to be running tslint anyways, and if I think of these sorts of errors more like linting errors, then it feels very natural to not prevent emitting code on those errors.
So, yeah, in summary, I think I agree with you, and thank you for working on this project :)
Would it be possible to send in a parameter to configure the transformer to report errors?
I suppose we could inspect the noEmitOnError
compiler option, if people really want that feature for some reason. Feel free to submit another issue as a feature request if so.
The pre-commit git hook solution doesn't work optimally for one of our teams working on an app. So in that scenario we'd prefer if the errors were reported when the TS is transformed 👍
This would be a great addition, I'll submit Feature request issue now:)