What’s New in TypeScript at Build 2016

TypeScript is about making JavaScript scale and building medium to large applications in JavaScript. JavaScript was never engineered for large applications, built in only 3 weeks as a response to Java. Intended 100 or up to 1000 lines. Today large scale applications have millions of lines of code.

What to do to make JavaScript for large scale applications? The TypeScript project. A statistically types superset of JavaScript that compiles in JavaScript. TypeScript built for any browser, any operating system. Open source hosted in GitHub.

  • Great tools enabled by static types

Use all the latest features of ECMAScript. A lot of features are not available in the wild. There is a gap between the state of the art JS and the state of the web JS. You need something to fill the gap. TypeScript allows you to use most of the features of ECMAScript 6 and down-level it to ECMAScript 3 for example. The gap continues to be there and you need tools like TypeScript to close the gap.

Visual Studio Code used for the entire session.

Rename a JavaScript .js file to the extension for TypeScript: .ts. This is a superset of JavaScript so we get to use additional features. e.g.: interface, array, lambda functions. Start the TypeScript compiler in watch mode to re-compile automatically. Change output to ECMAScript 6 in config to target the version you want. Refactoring capabilities because of semantic knowledge.

In the last year 4 versions released from 1.5 to 1.8. Roadmap on GitHub.

Features implemented in the last year

TS.PNG

Partnership with Google using TypeScript to write the next version of Angular, Angular 2.

  • Navigate around by going to declaration. Similar experience like with C# or Java.
  • Statement completion. IDE serves them up and validates them for you.
  • SystemJS module loader is great for development. Edit-Save-Refresh the browser.

React from Facebook, open source UI framework, also using TypeScript.

  • Based on JSX, write markup inside your program, allows you to write new attributes.
  • Go to definition on markup components.
  • Refactoring on JSX markup across large projects and have it type-safe.
  • Using Webpack with ts-loader to bundle all the code together.
  • Statement completion on the markup.
  • async await capability.
  • Visual Studio Code has Node debugging support.
    • Debugging and hitting breakpoint within the Node server.
  • Supporting JavaScript in TypeScript projects.
    • Using TypeScript infrastructure for JavaScript in Visual Studio and Visual Studio Code.
    • JSD annotation used for statement completion.
    • Statement completion for jQuery
      • tsc -install
      • tsd install jQuery
      • allowJS: true in tsconfig.js
    • tsd install loadash
  • Can mix and match two types of files: JavaScript and TypeScript. Gradual transition to TypeScript in a JavaScript project.

Features coming in the future

Next on the roadmap TypeScript 2, probably out in late May or in June.

TS2.PNG

  • Non-nullable types
    • Union types supported today: number | string.
    • Strict null checks will be introduced with TypeScript 2: undefined and null no longer available in types. Extracting in new types undefined and null. Can be used as union types, e.g. string | null | undefined.
    • New feature: definite assignment analysis to check that a value is assigned in all branches.
    • Type Checker checks JavaScript’s quirks.
    • Backwards compatible.

TS3

More new features:

TS4

TS5

Advertisements