Ability to disable TS8010: 'types' can only be used in a .ts file.
See original GitHub issueSearch Terms
TS8010 TS 8010 types can only be used in a .ts file ‘types’ can only be used in a .ts file
Suggestion
Ability to disable TS8010: ‘types’ can only be used in a .ts file. Type annotations could simply be ignore by tsc
when compiling a .js
file.
Use Cases
I work in a JS / TS blended codebase. My team uses WebStorm as our IDE, and it supports type annotations in .js files. When a variable/param is typed, it provides type-specific autocompletion. As you can imagine, that’s quite powerful when working in a JS environment. Consequently, we have thousands of type annotations throughout our JS files. We would like to add allowJs:true
to our tsconfig.json
, however tsc
throws an error for every type annotation in each JS file.
Checklist
My suggestion meets these guidelines:
- [ x ] This wouldn’t be a breaking change in existing TypeScript/JavaScript code
- [ x ] This wouldn’t change the runtime behavior of existing JavaScript code
- [ x ] This could be implemented without emitting different JS based on the types of the expressions
- [ x ] This isn’t a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
- [ x ] This feature would agree with the rest of TypeScript’s Design Goals.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:22
- Comments:17 (2 by maintainers)
Top Results From Across the Web
Error: 'types' can only be used in a .ts file - Visual Studio ...
Go to Extensions tab; Search for @builtin TypeScript and JavaScript Language Features; Click on Disable. Share.
Read more >how to solve Type annotations can only be used in TypeScript
This video is a solution for a problem caused in react native and react TypeScript. This problem generally occurs while creating ...
Read more >“Type annotations can only be used in TypeScript files.ts ...
one solution can be to disable the typescript check. so inside the settings.json add the below code line "javascript.validate.enable": false.
Read more >Static Type Checking
Static type checkers like Flow and TypeScript identify certain types of problems before you ... It is developed at Facebook and is often...
Read more >Typescript: 'type aliases' can only be used in a .ts file.
you must be using type aliases in .js file. To disable compiler errors in javascript, make sure that "allowJs" is set to false...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I am in a similar boat with Flow => TS migration. The ideal configuration during the migration is
checkJs: false
,allowJs: true
, so that we can import JS files (with Flow types) into the TS files. Buttsc
give me thousands of errors forType annotations can only be used in TypeScript files
when it tries to see if the JS files contain TS code and mistakes the Flow annotations for TS. We can compile the code using Webpack, but can’t do a static check in CI, with this setup.This could also be a valid use case for me. Indeed, I’m migrating an app from Flow to Typescript.
Right now, I’m using
allowJs: true
in my config and it enables me to import JS modules written in Flow into a TS modle with a working type-check in VSCode. However, if I runtsc --noEmit
to ensure that my ts files are valid, I get tons of TS8010 errors.Being able to disable this during the migration would really help us.