I’m creating a react project with this command npx react-native init projectName
,
It does create the project, however App.js
have typeScript code in it, it compiles just fine but VScode keeps throwing an error about annotations being a part of .ts
file only.
IK typescript, so if react does create typeScript code then why is the extension .js
.
Is there something that I’m doing wrong?
One more thing I’d like to add, If I manually change App.js
to App.tsx
the error does go away and it still works fine, but I don’t think that’s the right way to go, and I don’t intend to turn off javaScript checking is vs Code
Question posted in React native
The official React Native documentation can be found here.
The official React Native documentation can be found here.
2
Answers
It’s not typescript, but flow. More info: https://github.com/facebook/react-native/issues/29123
As mentioned in the other answer, what you are seeing in
App.js
is not TypeScript code. It is Flow, facebook’s own static type checker for JavaScript.If you want to use TypeScript then create project using this template:
You can find more details about TypeScript integration in React Native here:
https://reactnative.dev/docs/typescript