Languages Features Creators CSV Resources Challenges Add Language
GitHub icon

TypeScript

TypeScript - Programming language

< >

TypeScript is a programming language created in 2012 by Anders Hejlsberg.

#32on PLDB 11Years Old 217.0kUsers
56Books 8Papers 3mRepos

Try now: Web Β· Riju Β· TIO

TypeScript is a free and open-source programming language developed and maintained by Microsoft. It is a strict syntactical superset of JavaScript, and adds optional static typing to the language. Anders Hejlsberg, lead architect of C# and creator of Delphi and Turbo Pascal, has worked on the development of TypeScript. Read more on Wikipedia...


Example from Riju:
console.log("Hello, world!");
Example from hello-world:
console.log("Hello World");
// Hello world in TypeScript alert('Hello world!');
Example from Linguist:
console.log("Hello, World!");
Example from Wikipedia:
class Person { private name: string; private age: number; private salary: number; constructor(name: string, age: number, salary: number) { this.name = name; this.age = age; this.salary = salary; } toString(): string { return `${this.name} (${this.age}) (${this.salary})`; // As of version 1.4 } }

Language features

Feature Supported Token Example
MultiLine Comments βœ“ /* */
/* A comment
*/
Comments βœ“
// A comment
Algebraic Data Type βœ“
declare type numOrString = string | number
Line Comments βœ“ //
// A comment
Union Types βœ“
declare type numOrString = string | number
Single-Type Arrays βœ“
const scores: int[]
Type Inference βœ“
Strings βœ“ "
"hello world"
Type Parameters βœ“
function identity(arg: T): T {
   return arg;
}
Static Typing βœ“
Inheritance βœ“
class B {}
class A extends B {}
Print() Debugging βœ“ console.log
console.log("Hi")
Namespaces βœ“
// Typescript even supports splitting namespaces across multiple files:
// Validation.ts
namespace Validation {
    export interface StringValidator {
        isAcceptable(s: string): boolean;
    }
}
// LettersOnlyValidator.ts
/// 
namespace Validation {
    const lettersRegexp = /^[A-Za-z]+$/;
    export class LettersOnlyValidator implements StringValidator {
        isAcceptable(s: string) {
            return lettersRegexp.test(s);
        }
    }
}
Mixins βœ“
// https://www.typescriptlang.org/docs/handbook/mixins.html
class SmartObject implements Disposable, Activatable {
}
// Note: still need to do some runtime ops to make that work.
Interfaces βœ“
// https://www.typescriptlang.org/docs/handbook/interfaces.html
interface SquareConfig {
   color?: string;
   width?: number;
}
File Imports βœ“
import { ZipCodeValidator } from "./ZipCodeValidator";
/// 
/// 
import moo = module('moo');
/// 
Type Casting βœ“
something;
Classes βœ“
class Person {}
Booleans βœ“
const result = true
Generics βœ“
function identity(arg: T): T {
   return arg;
}
Abstract Types βœ“
abstract class Animal {}
class Dog extends Animal
Access Modifiers βœ“
class Person {
  private _age = 2
  public get age() {
    return _age
  }
  protected year = 1990
}
Static Methods βœ“
class Person {
  static sayHi() {
    console.log("Hello world")
  }
}
Enums βœ“
enum Direction {
 Up,
 Down
}
Scientific Notation βœ“
Binary Literals βœ“
// 0[bB][01]+n?
0b100110100000110011110010010
Floats βœ“
// (\.[0-9]+|[0-9]+\.[0-9]*|[0-9]+)([eE][-+]?[0-9]+)?
80766866.0
Hexadecimals βœ“
// 0[xX][0-9a-fA-F]+n?
0x4D06792
Octals βœ“
// 0[oO]?[0-7]+n?
0o464063622
Sets βœ“
set = new Set()
set.add("foo")
Function Composition βœ“
function o(f, g) {
   return function(x) {
       return f(g(x));
   }
}
Destructuring βœ“
const o = {p: 42, q: true};
const {p, q} = o;
Default Parameters Pattern βœ“
function multiply(a, b = 1) {
 return a * b;
}
Increment and decrement operators βœ“
let i = 0
i++
i--
Methods βœ“
class Person {
 method1() {}
 method2() {}
}
Functions βœ“
function helloWorld() {console.log("hi")}
Case Sensitivity βœ“
Zero-based numbering βœ“
While Loops βœ“
let times = 10
while (times) {times--}
console.log("done")
Ternary operators βœ“
let i = true ? 1 : 0
Switch Statements βœ“
var animal = "dog"
switch (animal) {
 case "dog": console.log("yay"); break;
 case "cat": console.log("oh"); break;
}
Letter-first Identifiers βœ“
References βœ“
Multiline Strings βœ“
const lines = `one
two`
Anonymous Functions βœ“
(() => console.log("hello world"))()
Infix Notation βœ“
const six = 2 + 2 + 2
Implicit Type Casting βœ“
console.log("hello " + 2)
Assignment βœ“
var name = "John"
Directives βœ“
"use strict";
"use asm";
Generators βœ“
function* fibonacci(limit) {
    let [prev, curr] = [0, 1];
    while (!limit || curr <= limit) {
        yield curr;
        [prev, curr] = [curr, prev + curr];
    }
}
// bounded by upper limit 10
for (let n of fibonacci(10)) {
    console.log(n);
}
// generator without an upper bound limit
for (let n of fibonacci()) {
    console.log(n);
    if (n > 10000) break;
}
// manually iterating
let fibGen = fibonacci();
console.log(fibGen.next().value); // 1
console.log(fibGen.next().value); // 1
console.log(fibGen.next().value); // 2
console.log(fibGen.next().value); // 3
console.log(fibGen.next().value); // 5
console.log(fibGen.next().value); // 8
// picks up from where you stopped
for (let n of fibGen) {
    console.log(n);
    if (n > 10000) break;
}
Garbage Collection βœ“
First-Class Functions βœ“
[2.0,1.1].map(Math.round)
Exceptions βœ“
try {
 undefinedFn()
} catch (err) {
 console.log(err)
}
hasDynamicTyping βœ“
Constants βœ“
const one = 1
Constructors βœ“
class Person {
 constructor(name) {
   this._name = name
 }
}
new Person("Jane")
Conditionals βœ“
if (true)
 console.log("hi!")
Method Chaining βœ“
"hello world".toString().substr(0, 1).length
Magic Getters and Setters βœ“
// Can be implemented in ES6 using proxies:
"use strict";
if (typeof Proxy == "undefined") {
    throw new Error("This browser doesn't support Proxy");
}
let original = {
    "foo": "bar"
};
let proxy = new Proxy(original, {
    get(target, name, receiver) {
        let rv = Reflect.get(target, name, receiver);
        if (typeof rv === "string") {
            rv = rv.toUpperCase();
        }
        return rv;
      }
});
console.log(`original.foo = ${original.foo}`); // "original.foo = bar"
console.log(`proxy.foo = ${proxy.foo}`);       // "proxy.foo = BAR"
Dynamic Properties βœ“
class Person {}
const person = new Person()
person.age = 50
Source Maps βœ“
{
 version: 3,
 file: 'min.js',
 names: ['bar', 'baz', 'n'],
 sources: ['one.js', 'two.js'],
 sourceRoot: 'http://example.com/www/js/',
 mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOC,IAAID;CCDb,IAAI,IAAM,SAAUE,GAClB,OAAOA'
};
Bitwise Operators βœ“
var x = 5 & 1;
Single Dispatch βœ“
Polymorphism βœ“
"a" + "b"; 1 + 2
Merges Whitespace βœ“
Lists βœ“
const list = [1,2,3]
Integers βœ“
80766866
Breakpoints βœ“
if (false)
  debugger
Partial Application βœ“
const addNumbers = (num1, num2) => num1 + num2
const add5 = num => addNumbers(10, num)
Map Functions βœ“
[1,2.1].map(Math.round)
Binary Operators βœ“
1 + 1
Async Await βœ“
async doSomething => await somethingElse()
Expressions βœ“
1 + 1
Regular Expression Syntax Sugar βœ“
console.log("Hello World".match(/\w/))
Statements βœ“
let x = 3;
Case Insensitive Identifiers X
Semantic Indentation X
Operator Overloading X
Multiple Inheritance X
Function Overloading X
Macros X
Processor Registers X
Multiple Dispatch X
Pointers X
Variable Substitution Syntax X

Books about TypeScript on goodreads

title author year reviews ratings rating
TypeScript for C# programmers Steve Fenton 2013 3 9 3.67
TypeScript for JavaScript Programmers Steve Fenton 2012 1 4 3.50

Books about TypeScript from ISBNdb

title authors year publisher
TypeScript Blueprints Wolff, Ivo Gabe de 2016 Packt Publishing
Beginning Angular 2 with Typescript Lim, Greg 2017 CreateSpace Independent Publishing Platform
Mastering TypeScript: Build enterprise-ready, modular web applications using TypeScript 4 and modern frameworks, 4th Edition Rozentals, Nathan 2021 Packt Publishing
Learn React with TypeScript 3: Beginner's guide to modern React web development with TypeScript 3 Rippon, Carl 2018 Packt Publishing
Vue.js 3 Cookbook: Discover actionable solutions for building modern web apps with the latest VueΒ features and TypeScript Ribeiro, Heitor Ramon 2020 Packt Publishing
The TypeScript Workshop: A practical guide to confident, effective TypeScript programming Grynhaus, Ben and Hudgens, Jordan and Hunte, Rayon and Morgan, Matt and Stefanovski, Wekoslav 2021 Packt Publishing
TypeScript 4 Design Patterns and Best Practices: Discover effective techniques and design patterns for every programming task Despoudis, Theo 2021 Packt Publishing
Essential TypeScript 4: From Beginner to Pro Freeman, Adam 2021 Apress
Advanced TypeScript Programming Projects: Build 9 different apps with TypeScript 3 and JavaScript frameworks such as Angular, React, and Vue O'Hanlon, Peter 2019 Packt Publishing
Programming with Types: Examples in TypeScript Riscutia, Vlad 2019 Manning
Advanced TypeScript Programming Projects: Build 9 different apps with TypeScript 3 and JavaScript frameworks such as Angular, React, and Vue O'Hanlon, Peter 2019 Packt Publishing
Hands-On Functional Programming with TypeScript: Explore functional and reactive programming to create robust and testable TypeScript applications Jansen, Remo H. 2019-01-30T00:00:01Z Packt Publishing
TypeScript Design Patterns Vane, Vilic 2016 Packt Publishing
Angular Projects: Build nine real-world applications from scratch using Angular 8 and TypeScript Mohammed, Zama Khan 2019 Packt Publishing
Deno Web Development: Write, test, maintain, and deploy JavaScript and TypeScript web applications using Deno Santos, Alexandre Portela dos 2021 Packt Publishing
Beginning Angular with Typescript (updated to Angular 5) Lim, Greg 2017 CreateSpace Independent Publishing Platform
Mastering TypeScript Rozentals, Nathan 2017 Packt Publishing
TypeScript Design Patterns Vane, Vilic 2016 Packt Publishing
TypeScript Revealed Maharry, Dan 2013 Apress
Angular for Material Design: Leverage Angular Material and TypeScript to Build a Rich User Interface for Web Apps Kotaru, Venkata Keerti 2019 Apress
TypeScript Blueprints Wolff, Ivo Gabe de 2016 Packt Publishing
TypeScript 2.x By Example: Build engaging applications with TypeScript, Angular, and NativeScript on the Azure platform Ohri, Sachin 2017 Packt Publishing
Learning TypeScript 2.x: Develop and maintain captivating web applications with ease, 2nd Edition Jansen, Remo H. 2018 Packt Publishing
Building Chatbots in TypeScript with the Microsoft Bot Framework: Programming Useful Bots in the Node.JS SDK Szul, Michael 2019 The October Foundation
TypeScript High Performance: Code for performance, use asynchronous programming, and deliver resources efficiently Kher, Ajinkya 2017-08-24T00:00:01Z Packt Publishing
PROGRAMMING TYPESCRIPT SHROFF
Design Patterns In Typescript Deepak Sukdeo Sapkale 2019 Independently Published
TypeScript Programming(Chinese Edition) [ MEI ] BAO LI SI QIE ER NI 2020 China Electric Power Press
"TypeScript Programming Notebook: A TypeScript Programming Notebook Diary For Daily Use" https://isbndb.com/book/9781686791451 LLC Publishing, Sanders Industries 2019 Independently published
Typescript Programming Zoltan Arvai and Attila Hajdrik 2013 Wrox
Refactoring TypeScript James Hickey 20191018 Packt Publishing
TypeScript Microservices Parth Ghiya 30-05-2018 Packt Publishing
Mastering TypeScript Nathan Rozentals 2015-04-23 Packt Publishing
Effective TypeScript Dan Vanderkam 20191017 O'Reilly Media, Inc.
Learning TypeScript Josh Goldberg 20220603 O'Reilly Media, Inc.
TypeScript Quickly Anton Moiseev; Yakov Fain 20200210 Simon & Schuster
Programming TypeScript Boris Cherny 20190425 O'Reilly Media, Inc.
TypeScript Essentials Christopher Nance 20141021 Packt Publishing
TypeScript High Performance Ajinkya Kher 2017-08-24 Packt Publishing
The TypeScript Workshop Ben Grynhaus; Jordan Hudgens; Rayon Hunte; Matt Morgan; Wekoslav Stefanovski 29-07-2021 Packt Publishing
Mastering Typescript Programming Techniques Tamas Piros 2018
TypeScript for Beginners Sufyan bin Uzayr 20220323 Taylor & Francis
Mastering TypeScript 3 Nathan Rozentals 28-02-2019 Packt Publishing
Typescript Programming Language Typescript Publishing 2019-11-18 Independently Published
Design Patterns In Typescript Dimitris Loukas
TypeScript 3.0 Quick Start Guide Patrick Desjardins 2018-08-30 Packt Publishing
Mastering TypeScript - Second Edition Nathan Rozentals 2017-02-24 Packt Publishing
Angular Development with TypeScript Anton Moiseev; Yakov Fain 20181205 Simon & Schuster
Developing Web Components with TypeScript JΓΆrg Krause 20210312 Springer Nature
Hands-On Functional Programming with TypeScript Remo H. Jansen 30-01-2019 Packt Publishing
TypeScript 2.x for Angular Developers Christian Nwamba 20171207 Packt Publishing
TypeScript 4 Design Patterns and Best Practices Theo Despoudis 15-09-2021 Packt Publishing
Learn TypeScript 3 by Building Web Applications Sebastien Dubois; Alexis Georges; Basarat Ali Syed 22-11-2019 Packt Publishing
Hands-On TypeScript for C# and .NET Core Developers Francesco Abbruzzese 31-10-2018 Packt Publishing

Publications about TypeScript from Semantic Scholar

title authors year citations influentialCitations
Understanding TypeScript G. Bierman and M. Abadi and Mads Torgersen 2014 158 23
Safe & Efficient Gradual Typing for TypeScript Aseem Rastogi and N. Swamy and C. Fournet and G. Bierman and Panagiotis Vekris 2015 93 12
Concrete Types for TypeScript G. Richards and Francesco Zappa Nardelli and J. Vitek 2015 46 7
Checking correctness of TypeScript interfaces for JavaScript libraries Asger Feldthaus and Anders MΓΈller 2014 38 0
An empirical investigation of the effects of type systems and code completion on API usability using TypeScript and JavaScript in MS visual studio Lars Fischer and Stefan Hanenberg 2015 14 0
Mixed Messages: Measuring Conformance and Non-Interference in TypeScript Jack Williams and J. Garrett Morris and P. Wadler and Jakub Zalewski 2017 11 1
Static TypeScript: an implementation of a static compiler for the TypeScript language T. Ball and J. D. Halleux and Michal Moskal 2019 5 1
To Type or Not to Type? A Systematic Comparison of the Software Quality of JavaScript and TypeScript Applications on GitHub J. Bogner and Manuel Merkel 2022 1 0
haskell.html Β· typescript.html Β· lisp.html

View source

- Build the next great programming language Β· Search Β· Day 213 Β· About Β· Blog Β· Acknowledgements Β· Traffic Β· Traffic Today Β· GitHub Β· feedback@pldb.com