How to use TypeScript in create-react-app application?
Starting from [email protected] or higher, there is a built-in support for typescript. i.e, create-react-app now supports typescript natively. You can just pass –typescript option as below
1 2 3 4 5 | npx create-react-app my-app --typescript # or yarn create react-app my-app --typescript |
But for lower versions of react scripts, just supply –scripts-version option as react-scripts-ts while you create a new project. react-scripts-ts is a set of adjustments to take the standard create-react-app project pipeline and bring TypeScript into the mix.
Now the project layout should look like the following:
1 2 3 4 5 6 7 8 9 10 11 12 | my-app/ ├─ .gitignore ├─ images.d.ts ├─ node_modules/ ├─ public/ ├─ src/ │ └─ ... ├─ package.json ├─ tsconfig.json ├─ tsconfig.prod.json ├─ tsconfig.test.json └─ tslint.json |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.