React Installation and Setup
To use typescript with react in a node project, you must first have a project directory initialized with npm. To initialize the directory with npm init
Installing via npm or yarn
You can install React using npm by doing the following:
Facebook released its own package manager named Yarn, which can also be used to install React. After installing Yarn you just need to run this command:
You can then use React in your project in exactly the same way as if you had installed React via npm.
Installing react type definitions in Typescript 2.0+
To compile your code using typescript, add/install type definition files using npm or yarn.
or, using yarn
Installing react type definitions in older versions of Typescript
You have to use a separate package called tsd
Adding or Changing the Typescript configuration