Skip to main content

Introduction

Less than 1 minute

Introduction

  • TS or TypeScript is a programming language that compiles to JavaScript
  • It is a superset of JavaScript, so any valid JavaScript code is valid TypeScript code
  • Benefits:
    • Tooling: catch bugs while coding in your editor
    • You can work with types, interfaces, generics, ...
    • Write most recent JavaScript features and transpile them to the JS version you want to use
  • Goals:
    • Provide an optional type system for JavaScript
    • Provide planned features from future JavaScript editions to current JavaScript engines

Type system

  • Why add types to JavaScript?
    • Allows compiler to catch errors while coding
    • Types increase the readability of your code
    • Great form of documentation

Your JavaScript is TypeScript

  • TypeScript provides compile time type safety for your JavaScript code
  • Types are completely optional!
  • You can simply change the .js extension to .ts
  • TypeScript is intentionally and strictly a superset of JavaScript with optional type checking ts is js

Types can be implicit

  • Even if you don't explicitly define a type, TypeScript will infer it:
let foo = 123;
foo = '456'; // Compile error: cannot assign `string` to `number`

// Is foo a number or a string?

Types can be explicit

  • You can explicitly define a type:
let foo: number = 123;