ds300 / react-native-typescript-transformer

Seamlessly use TypeScript with React Native
MIT License
657 stars 50 forks source link

Errors that you would expect to get by running the typescript compiler are not being reported by the transformer #13

Closed aarondail closed 7 years ago

aarondail commented 7 years ago

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: https://github.com/Microsoft/TypeScript/issues/4864

Do you have any idea how we could fix this?

Thanks! Aaron

ds300 commented 7 years ago

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.

aarondail commented 7 years ago

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 :)

cbrevik commented 7 years ago

Would it be possible to send in a parameter to configure the transformer to report errors?

ds300 commented 7 years ago

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.

cbrevik commented 7 years ago

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 👍

almostintuitive commented 6 years ago

This would be a great addition, I'll submit Feature request issue now:)