Statically typed superset of JavaScript
From Microsoft in 2012
Familiar names such as Anders Hejlsberg
let x = 5;x = "cat";
let x: number = 5;x = "cat";
let x: number = 5;
let x = 5;
TypeScript is not a new programming language
Follows the JavaScript language standard and semantics
5 + 'cat' is allowed
5 + 'cat'
Does not have its own runtime
TypeScript uses a structural type system
C# uses a nominal type system
class A {};class B {};const item = new A();const item2 : B = item;
function makePerson(name) { return { name: name };}function printPerson(person) { console.log(person.name);}
interface Person { name: string;}function makePerson(name: string) { return { name: name };}function printPerson(person: Person) { console.log(person.name);}printPerson({ name: "Dave" });
type Person = { name: string;}function printPerson(person: Person) { console.log(person.name);}
Null was invented in 1965
Called "the million dollar mistake"
function uppercaseString(str) { return str.toUpperCase();}
function uppercaseString(str: string | null) { if (str !== null) { return (str.toUpperCase()); }}
Generics
Enumerations
Class visibility: private, public...
Literal types
Decorators
Refactoring
Hopefully first-party
DefinitelyTyped
npm install @types/mylibrary
🙏
Roll your own
Vue is being rewritten in TypeScript
Over 5,000 JavaScript libraries
TypeScript compiler gets 4,039,800 downloads a week
typescriptlang.org
TypeScript Playground
TypeScript Handbook
Visual Studio Code