Menu

React, etc. Tech Stack

React, Flux, GraphQL, Hack, HHVM...? All of this and more!

TypeScript in create-react-app

Create React App is the official boilerplate for React applications. In the recent major upgrade it received support for Babel 7 and other major tooling. Meanwhile TypeScript has also improved interoperation with Babel, but the two weren't available in create-react-app 2.0.

Now this is changing, with the merging of TypeScript support in create-react-app. The feature is now complete and slated for release with version 2.1. This integration builds heavily on the Babel 7 cooperation, and is a native feature.

This is a great improvement for React developers looking to use TypeScript. With the official boilerplate now supporting the Microsoft-developed, but widely adopted, superscript of JavaScript, developers will need to spend less time shaving the yak. Taking TypeScript into use in create-react-app 2.1 is simple:

$ npm install --save typescript @types/node @types/react @types/react-dom @types/jest

The Yarn packet manager equivalent works just as fine. The next step is to rename JavaScript files to TypeScript (rename .js files to .tsx - JSX for TypeScript). Next just restart your dev server and you're done.

Instead of spending time on bespoke, developers can now look a standard reference implementation to leverage the typing, debugging and other powerful features provided by TypeScript. Read the full details on the feature, and how to use TypeScript: Adding TypeScript to create-react-app

Written by Jorgé on Sunday October 21, 2018

Permalink - Tags: react, typescript

« The future of PHP 8 unclear - Rawact compiles React.js components to pure JavaScript »