Note: this feature is available with
[email protected]and higher.
To start a new Create React App project with TypeScript, you can run:
npx create-react-app my-app --template typescript# oryarn create react-app my-app --template typescript
If you've previously installed
npm install -g create-react-app, we recommend you uninstall the package using
npm uninstall -g create-react-appto ensure that
npxalways uses the latest version.
Global installs of
create-react-appare no longer supported.
To add TypeScript to a Create React App project, first install it:
npm install --save typescript @types/node @types/react @types/react-dom @types/jest# oryarn add typescript @types/node @types/react @types/react-dom @types/jest
Next, rename any file to be a TypeScript file (e.g.
src/index.tsx) and restart your development server!
Type errors will show up in the same console as the build one. You'll have to fix these type errors before you continue development or build your project. For advanced configuration, see here.
Getting Started with TypeScript and React
You are not required to make a
tsconfig.json file, one will be made for you. You are allowed to edit the generated TypeScript configuration.
- TypeScript Handbook
- TypeScript Example on React
- React + TypeScript Cheatsheets has a good overview on how to use React with TypeScript
If your project is not created with TypeScript enabled, npx may be using a cached version of
create-react-app. Remove previously installed versions with
npm uninstall -g create-react-app (see #6119).
Constant enums and namespaces are not supported, you can learn about the constraints of using Babel with TypeScript here.