O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Global libraries

Yeah, TypeScript is, indeed, an impressive language when it comes to writing a new code. But what about existing none-TypeScript libraries? For example, we are going to use React and Redux modules. They are written in JavaScript, not in TypeScript. Luckily, mainstream libraries are already provided with TypeScript declaration files. We can install these files per module using npm:

npm i -D @types/react 
npm i -D @types/react-dom 

Now, when we try something stupid with any of these modules, we get immediately notified about the problem:

import * as React from "react"; 
import * as ReactDOM from "react-dom"; 
 
ReactDOM.render( 
  <div></div>, 
  "root" 
); 

On compiling or even while typing, you will get the error:

 error TS2345: Argument ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required