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

Basic types

The development environment now seems ready, so we can try it out with an elementary example:

example.ts

let title: string = "RSS Aggregator"; 

We use the type annotation feature of TypeScript to set a constraint on the variable. That's so easy; we just extend the declaration with the so-called declaration space like :type, where type can be one of the basic types (boolean, number, string, array, void, any, and a few others), class, interface, type alias, enum, and import. Here, we applied string, meaning title accepts only strings.

After compiling with npm run build, we can find file example.js in the ./build directory with the following content:

build/example.js

let title = "RSS Aggregator"; 

You see it doesn't do much; it ...

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