Home > Software design >  React native, main file is in wrong extension
React native, main file is in wrong extension

Time:08-06

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

CodePudding user response:

It's not typescript, but flow. More info: https://github.com/facebook/react-native/issues/29123

CodePudding user response:

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:

npx react-native init MyApp --template react-native-template-typescript

You can find more details about TypeScript integration in React Native here: https://reactnative.dev/docs/typescript

  • Related