TypeScript is an open source programming language created in 2012 by Anders Hejlsberg.
git clone https://github.com/microsoft/TypeScript
#21on PLDB | 12Years Old | 3mRepos |
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...
console.log("Hello, world!");
console.log("Hello World");
// Hello world in TypeScript
alert('Hello world!');
console.log("Hello, World!");
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
}
}
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 |
|
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 /// |
|
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"; /// |
|
Type Casting | โ |
|
|
Classes | โ | class Person {} |
|
Booleans | โ | const result = true |
|
Generics | โ | function identity |
|
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 |