TypeStrong / atom-typescript

The only TypeScript package you will ever need
https://atom.io/packages/atom-typescript
MIT License
1.13k stars 205 forks source link

Question: .tsx are parsed properly, .ts have many errors #1507

Closed rahamin1 closed 5 years ago

rahamin1 commented 5 years ago

I am using atom 1.31.0 with atom-typescript 13.2.1.

Parsing of .tsx files is fine. However, when I rename a .tsx file to .ts, I get many errors.

I checked in atom-typescript, and TypeScript file extensiuon is set to the default value (.ts, .tst, .tsx).

Any idea?

lierdakil commented 5 years ago

Hi. First of all, consider updating your Atom and Atom-TypeScript installations, Atom 1.31.0 is rather old by this point.

Well, I can tell you that it's not the intended behaviour. Since I don't have enough context information to actually pinpoint the issue, here are a few random ideas:

  1. tsx is actually different from ts in that, unlike the latter, the former allows JSX syntax. JSX being an HTML-like embedded syntax in JavaScript (or TypeScript in this case) popularized by the React framework. So if you have JSX code in your file, renaming it to .ts effectively turns all JSX into syntax errors.
  2. Tsserver, which is used as a backend for Atom-TypeScript, can be a bit capricious with new files sometimes. It may fail to realize that your newly-renamed file is a part of the same project that it was before you renamed it, for instance. Restarting tsserver is usually an effective and easy enough workaround for this sort of problems: Atom-TypeScript implements this via typescript:restart-all-servers command. Also see our FAQ for more information.
  3. On a related note, another thing to check is your tsconfig.json. If the file globs (includes and excludes; or if you're using deprecated files, first of all, don't, and second, add the new filenames there) in that file do not include .ts files, then tsserver won't pick up those files as part of that project, which will lead to all kinds of fun error reports, from being unable to find modules, to invalid syntax being used if you're using syntax extensions (like decorators for instance), to really obscure errors about missing some support library.
  4. Every so often we get bugreports along the lines of "I get thousands of syntax errors reported in my TS files that do not even make sense in TS". In the absolute majority of cases, it turns out that Atom-TypeScript isn't the source of those error reports though -- usually it's some other overeager package, like eslint for instance, trying to parse TypeScript and failing at it miserably. Since many linter-type packages use the same error reporting interface as Atom-TypeScript, the confusion is understandable.
rahamin1 commented 5 years ago

Thanks! (1) explains it... I have jsx.