If you have already created the Create React App project, you need to import typescript
Step 1:
NPM install --save typescript @types/ node@types/reacte@types/react-dom@types /jest or yarn add typescript @types/node @types/react @types/react-dom @types/jestCopy the code
Step 2:
Rename any JavaScript files in your project with the suffix ‘.js’ to TypeScript files with the suffix ‘.tsx ‘(e.g. SRC /index.js to SRC /index.tsx)
After completing the previous steps, an error is reported if the project is running:
ENOENT: no such file or directory, open 'D:\zxz\learn-react\redux-education\src\index.js'
Copy the code
The dependency running project needs to be re-installed
There are some errors in the original content
For example, sometimes the following error occurs when ts is configured with redux
Could not find a declaration file for module 'react-redux'. 'D:/zxz/learn-react/redux-education/node_modules/react-redux/lib/index.js' implicitly has an 'any' type.
Try `npm install @types/react-redux` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-redux'; `
Copy the code
To change the
const { Provider } = require('react-redux');
Copy the code