React-native: Type annotations can only be used in TypeScript files.ts(8010) on React-Native CLI Startup

Created on 12 Jun 2020  Â·  8Comments  Â·  Source: facebook/react-native

Please provide all the information requested. Issues that do not follow this format are likely to stall.

Description

I have created like 2 starter project in ReactNative using npx react-native init [projectName], and that error in the title always comes with the starter code, precisely on line 27.

React Native version:

System:
OS: Windows 10 10.0.18362
CPU: (2) x64 Intel(R) Celeron(R) 2957U @ 1.40GHz
Memory: 1.76 GB / 7.89 GB
Binaries:
Node: 12.17.0 - C:\Program Filesnodejsnode.EXE
Yarn: 1.22.4 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
npm: 6.14.4 - C:\Program Filesnodejs\npm.CMD
Watchman: Not Found
SDKs:
Android SDK: Not Found
IDEs:
Android Studio: Version 3.6.0.0 AI-192.7142.36.36.6392135
Languages:
Java: javac 12
Python: Not Found
npmPackages:
@react-native-community/cli: Not Found
react: 16.11.0 => 16.11.0
react-native: 0.62.2 => 0.62.2
npmGlobalPackages:
react-native: Not Found

Steps To Reproduce

Provide a detailed list of steps that reproduce the issue.

  1. Create a new react native project
  2. Open the starter code from any editor, i use VScode.
  3. Go to App.js and scroll to line 27.
  4. Hold on a little bit then the error would occur.

Expected Results

Since it is a starter code from the react-native team, which helps new developers to understand the codebase and how it works, that error should not be there. It can scare a new developer coming into ReactNative.

Snack, code example, screenshot, or link to a repository:

react_errorr

Needs

Most helpful comment

Quick fix:
Set "javascript.validate.enable": false in your VS Code settings.

All 8 comments

Getting same issue ....
Screenshot from 2020-06-15 12-57-20

:100: This can be closed now. The answer is correct!

Does anyone have the solution to this ???

Hi all the reason for this is that React Native template ships with a flow config. This error is a result of your VSCode plugins not working playing well with flow.

https://stackoverflow.com/questions/48859169/js-types-can-only-be-used-in-a-ts-file-visual-studio-code-using-ts-check

This should help you resolve the error!

Quick fix:
Set "javascript.validate.enable": false in your VS Code settings.

https://stackoverflow.com/a/50726464/7344761

This worked for me ..quick fix!!
Simply go to VS Code >>File>>Preferences>>Settings >> go to javascript(or search javascript and scroll down)>validate> enable/disable >>disable or uncheck

Was this page helpful?
0 / 5 - 0 ratings