mirror of
https://github.com/zhigang1992/create-react-app.git
synced 2026-01-13 09:00:30 +08:00
1.4 KiB
1.4 KiB
id, title
| id | title |
|---|---|
| adding-typescript | Adding TypeScript |
TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
Recent versions of TypeScript work with Create React App projects out of the box thanks to Babel 7. Note that Babel 7 TypeScript does not allow some features of TypeScript such as constant enum and namespaces.
To add TypeScript to a Create React App project, follow these steps:
- Run
npm install --save typescript @types/react @types/react-dom @types/jest(oryarn add typescript @types/react @types/react-dom @types/jest). - Rename the
.jsfiles you want to convert: use.tsxif they use JSX or.tsif not (e.g.git mv src/index.js src/index.tsx). - Create a
tsconfig.jsonfile at the root project directory with{}in it. Alternatively, renameindex.jstoindex.tsx. - Restart your development server (if applicable). This will set sensible defaults and the required values in your
tsconfig.jsonfile.
Type errors will show up in the same console as the build one.
We recommend using VSCode for a better integrated experience.
To learn more about TypeScript, check out its documentation.