Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Code:[js] types can only be used in a .ts file

Is it possible to use .js files in a typescript project in vs code? I have clone a react-native project from a github repository and opened it in visual studio code. When I add a tsconfig.json in order to start using typescript, I get a long list of errors. For example here is a drawer.js file (with es6 features):

enter image description here

Here is my tsconfig.json file (If I remove this file then every thing works fine, no error reported) :

enter image description here

like image 417
TheSoul Avatar asked Dec 25 '16 10:12

TheSoul


People also ask

Can we use JS in TS file?

The allowJs setting allows JavaScript files to be imported inside your TypeScript files. The setting basically allows JavaScript and TypeScript files to live in the same project. The allowJs option is set to false by default.

What is TS file in VS Code?

TypeScript in Visual Studio Code. TypeScript is a typed superset of JavaScript that compiles to plain JavaScript. It offers classes, modules, and interfaces to help you build robust components.


2 Answers

I restarted VS code and the error was gone, just in case it helps

like image 54
RoRFan Avatar answered Sep 17 '22 18:09

RoRFan


Has that change the "Select Language Mode" for "TypeScript React" in list. it worked for me.

enter image description here

like image 25
Erick Barreto Avatar answered Sep 21 '22 18:09

Erick Barreto