Top 1,000 Features Creators Resources Extensions Blog Explorer CSV Download
GitHub icon

TypeScript

< >

TypeScript is an open source programming language created in 2012 by Anders Hejlsberg.

#14on PLDB 12Years Old 3mRepos
Download source code:
git clone https://github.com/microsoft/TypeScript

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
}
Case Insensitive Identifiers X
Semantic Indentation X
Operator Overloading X

View source

- Build the next great programming language ยท About ยท Acknowledgements ยท Published by Breck's Lab