Typescript is added to the version 16 react application created with create react app. I have installed the latest v.18 version of @types/react and @types/react-dom, but I would like to know if it is a problem that the version is different from react. Thank you.
CodePudding user response:
Yes, as you'll have TS types for React 18, but JS code for React 16. For example, you may be able to import a new feature from React 18 but get a runtime error because you only have React 16.
You can solve this by using @types/react
and @types/react-dom
version 16 until you're ready to upgrade to React 18.
CodePudding user response:
npx typesync will resolve type syncing issues.
You can go a step further and add this in your package.json:
“postinstall”: “npx typesync”
Now every time you install or update your packages you’ll automatically run the postinstall script!