TypeScript for Node.Js

"Tame your JavaScript"

Jeremy Likness

Cloud Developer Advocate for Microsoft
  • 20 Years Professional Developer
  • Author of books and articles, both online and print
  • Prolific speaker
  • 100% plant-based diet and CrossFit

Wat?!


						
...

Evolution

Harmony? ECMAScript 2015? Babel?

Popular options.

Includes: classes, lexical scope, lambda...

Lacks …

  • Interfaces
  • Dynamic module affinity (System.js, Require.js, etc.)
  • External library definitions
  • Generics

Real World

Discovery

Intent is clearer with types and interfaces.

Real World

Documentation

Libraries make it easier to discover and learn how to use APIs.

Real World

Development Time Security

Less "fat-finger", catch bugs earlier in the cycle.

Real World

Scope Safety

Modules, Classes, and Lambdas take care of this.

Real World

Team Scale

Easier for multiple teams and members to work in parallel.

Real World

Increased Velocity

Team had 4x velocity with TypeScript vs. just JavaScript. Oh, and the Angular team uses it, for goodness' sake!

Demo Time!

TypeScript and Node.js

  • First class support
  • IDE integration
  • Libraries (and automatic generation)
  • Configurable options

Getting Started

  • npm init -y
  • npm i typescript --save-dev
  • npm i @types/node --save-dev
  • node tsc --init

Demo

Examining tsconfig.json.

The App

  • Edit tsconfig.json
  • Add "main": "lib/main" and "types": "lib/main" to package.json
  • Create src directory
  • Add code
  • Build and run!

Demo

First app.

Demo

Full enchilada.

https://github.com/JeremyLikness/micro-locator

Questions?

@JeremyLikness

https://blog.jeremylikness.com/

https://github.com/JeremyLikness/typescript-for-node