Upgrade to Pro — share decks privately, control downloads, hide ads and more …

TypeScript

 TypeScript

An intro into TypeScript

And a small project developed with my learnings
https://github.com/LucasArruda/cacher

Lucas Arruda

June 04, 2021
Tweet

More Decks by Lucas Arruda

Other Decks in Programming

Transcript

  1. What is TypeScript • An open-source language that gets transpiled

    (transformed) to JavaScript • Superset of JavaScript and interchangeable with it (adoption is gradual) • All valid JavaScript code is TS • Adds static type definition to JS • Provides annotations and better documentation of JS code • Validates JS code automatically • Generates output that runs anywhere (because it's vanilla JS)
  2. What it is not • A fix for JS issues

    (NaN === NaN being equal to false) • Meant to replace Javascript • Meant to be used directly (without being transpiled) • Fully independent (controlled by Microsoft) • Babel (something that adds new features and compiles to old JS) • A definitive solution (JS is evolving quickly and that might kill TS in the future)
  3. Variables // All valid const name:string = "Joe" // Declare

    everything + assign value let name:string; // Declare everything let name; // Declare JS way let name = "Joe" // Declare JS way + assign (type is inferred)
  4. Composing Types - Unions Not only can we infer types,

    but we can restrict them to a set: