TheSoul
TheSoul

Reputation: 5346

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

Upvotes: 13

Views: 25128

Answers (4)

Swapnil Patwa
Swapnil Patwa

Reputation: 4089

NOTE - This is just a WORKAROUND, not solution. Use ONLY IF you do not find appropriate solution

Workaround - Add the following configuration in $workspace/.vscode/settings.json

{
    "javascript.validate.enable": false
}

Upvotes: 7

Erick Barreto
Erick Barreto

Reputation: 11

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

enter image description here

Upvotes: 1

Alex Alberto Robaina
Alex Alberto Robaina

Reputation: 59

You can try with this!!!

Install in your visual studio code the extension Flow Language Support and disable TypeScript and JavaScript Language Features

Search @builtin TypeScript and JavaScript Language Features and reload.

You can see this solutions https://stackoverflow.com/questions/48859169

Its important install npm for flow

Link Flow

Upvotes: 1

RoRFan
RoRFan

Reputation: 424

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

Upvotes: 9

Related Questions