['type aliases' can only be used in a .ts file] ['type aliases' can only be used in a .ts file] reactjs reactjs

['type aliases' can only be used in a .ts file]


This is what you need to do with VS Code, observe the gif carefully

Steps to resolve error1. Go to extension2. Click on more (...) and select Show Built-in extension3. Search "TypeScript and JavaScript Language Features" - yellow & blue icon4. Click on Setting icon of extension and select Disable (workspace)5. Click on Reload / Restart Required


If you are getting this in React Native its probably a known bug in VSCode, that when Google Flow (which competes with MS Typescript) is coded, shows errors erroneously mentioning Typescript.

Your current .js code is supposed to be preprocessed by Flow into another .js file with "proper" js.

So make sure Flow is installed and then disable the Typescript parsing support. Here's the official answer on the Flow installation webpage:

Set javascript.validate.enable option to false or completely disable the built-in TypeScript extension for your project (see gif below)...

Otherwise, you may want to stay as is and just change your code as suggested by C2P1 on March 19, 2018 on the github issue 631

To disable the [js] parser (connected to Typescript),

In VSCode menu: File -> Preferences -> User settings, (or ctrl+,) and add the following line

"javascript.validate.enable": false,

This answer was completed after seeing Idan Dagan's answer (Not the accepted answer) here: js 'types' can only be used in a .ts file - Visual Studio Code using @ts-check

And here's an excellent albeit old page about setting up the react-native environment, from Hackernoon. (You also have the VSCode React-native-full plugin)


Just disable built-in extension for TypeScript in VSCode. On the VSCode Extensions choose "Show Built-in Extensions" and then search for "TypeScript and JavaScript Language Features", Click disable then reload the VSCode. It works for me