Using TypeScript when creating React web apps with "create-react-app" (CRA)
Posted: (EET/GMT+2)
Many of my current web development projects use Facebook's React UIs, and I've grown to like this technology a lot lately. However, unlike Angular, React doesn't have built-in support for TypeScript. Personally, I don't see any reason why you wouldn't develop JavaScript code with TypeScript, perhaps with the exception of very simple projects and or proofing concepts.
Now, Facebook has created a very useful NPM package called "create-react-app", which bootstraps a ready-made React application with simple command-line commands. But, it's all JavaScript.
Yes, Visual Studio's ASP.NET Core templates contain a React+TypeScript combination, but this template isn't known outside Visual Studio circles, so I've been happy to learn (thanks, JK) about an extension to "create-react-app", simply called "create-react-app-typescript".
This NPM package converts the application template to support TypeScript, which is great. To run the extension, you would add the "scripts" extra parameter to "create-react-app", as follows:
npm install -g create-react-app create-react-app my-app --scripts-version=react-scripts-ts cd my-app/ npm start
The TypeScript extension package is freely available on NPM, so I recommend giving it a try.
Happy React development with TypeScript!