8

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
}

3 Answers 3

7
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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

8 Comments

Okay done, does react native expect the user's default app.js to support flow?
Yes as Flow is a tool built by Facebook, which is also behind React Native.
Okay i'll look into installing it haha. Thank you
You'll be much better off learning TypeScript, Flow is practically dead nowadays. You don't need to learn any of them if you prefer to stick to JavaScript
First time I've heard of both. What use does a language like typescript or flow have to react native apps?
|
1

It is Flow not TypeScript as mentioned Yanick.

VSC doesn't support it by default, so if you want to keep it the way it is, you can just install Flow Language Support extension in your IDE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.