3

I have a bunch of JS file that I would like to convert to TS files without having to add any typing or introducing a lot of changes. I know I can use // @ts-ignore on the lines that I want the compiler to ignore, but is there a way to ignore the entire file?

I still would like to output a JS file, but as is, with all the errors ignores.

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
Alkasai
  • 3,757
  • 1
  • 19
  • 25
  • Possible duplicate of [How can I disable all typescript type checking?](https://stackoverflow.com/questions/54506744/how-can-i-disable-all-typescript-type-checking) – Karol Majewski Feb 24 '19 at 00:51

1 Answers1

1

It's easy. Don't rename the file to .ts (until you want to deal with the errors), and use the following configuration

 {
    "compilerOptions": {
      "allowJs": true,
      "checkJs": false,
      "rootDir": "src", 
      "outDir": "dist"
    }
 }

TypeScript will transpile your JavaScript files along with your TypeScript files and provide as much intellisense as possible.

I've answered a similar question in greater detail here: https://stackoverflow.com/a/49640454/1915893

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84
  • that's an option, though i'm not sure that will work for me. 1) what kind of intellisense would it provide? 2) my output files are in the same location as the original files so it would be overriding itself. – Alkasai Feb 23 '19 at 20:03
  • To use this option you would need to output to a separate directory. You would get as much intellisense as the language can provide in the absence of type annotations, which is a lot. If you reference typescript files or packages that have type declarations than such information will be surfaced in your JavaScript files, for example to provide auto-completion, but your usage would still not be checked, which is I believe the point. – Aluan Haddad Feb 23 '19 at 20:06
  • I understand that I would have to output this in a separate location, but unfortunately, this is not an option at this moment. – Alkasai Feb 23 '19 at 20:10
  • Then you'll need to use the TS ignore directive like you said. I don't know why it would be a problem outputting to a separate directory. It depends on the kind of project I suppose but if you're using TSC to produce your output then it shouldn't be a problem – Aluan Haddad Feb 23 '19 at 20:14
  • thank you, I'll think about it. at the moment I wish there was an ignore directive for the entire file. – Alkasai Feb 23 '19 at 20:23
  • ah, thank you. that makes some sense, though I wish this was supported in TS. as someone commented it would be a good tool during the transition to TS. – Alkasai Feb 23 '19 at 20:30