Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Typescript annotation error for default React Native app?

Tags:

react-native

When creating a fresh React Native project and opening the default app.js file in VSCode, this line;

const App: () => React$Node = () => {

returns

Type annotations can only be used in TypeScript files.

as a VSCode problem.

Am I suppose to have typescript installed with React Native, or is this some kind of other issue with VSCode or something? Surely React Native isn't releasing their default app.js file with an error.

Here's the contents of the problem.

{
    "resource": "/d:/App/sw_lbi_app/App.js",
    "owner": "typescript",
    "code": "8010",
    "severity": 8,
    "message": "Type annotations can only be used in TypeScript files.",
    "source": "ts",
    "startLineNumber": 27,
    "startColumn": 12,
    "endLineNumber": 27,
    "endColumn": 28
}
like image 864
srb633 Avatar asked May 02 '20 19:05

srb633


2 Answers

const App: () => React$Node = () => {

Type annotations can only be used in TypeScript files.

In case you want to leave this line of Facebook's code to stay peacefully in Microsoft's VS Code, there is a Setting switch to turn off the TypeScript-style validation in a .js file.

Open Preferences => Settings, search javascript.validate, and locate

js validation

Uncheck it, and re-open App.js file. The validation will be gone.

PS: There is an option to make this setting change in User scope or Workspace scope.

like image 77
themefield Avatar answered Nov 03 '22 17:11

themefield


That's Flow, not TypeScript. Simply remove the types and your code will run without problem.

like image 27
emeraldsanto Avatar answered Nov 03 '22 18:11

emeraldsanto