26 changes · 0 breaking
01Static Type AnnotationsTypeScript 1.0

Optional type annotations for variables, parameters, and return types layered on top of JavaScript.

javascript
function greet(name: string): string {
return 'Hello, ' + name;
}
02Interfaces & Structural TypingTypeScript 1.0

Named structural contracts — types are compatible if they share the right shape, not by name.

javascript
interface Animal {
name: string;
sound(): string;
}
03GenericsTypeScript 1.0

Type-safe parameterized abstractions that preserve type information through transformations.

javascript
function identity<T>(arg: T): T { return arg; }
const n = identity(42); // T = number
const s = identity('hi'); // T = string
04Enums & ClassesTypeScript 1.0

Enum types for named constants and class syntax with access modifiers (public, private, protected).

javascript
enum Direction { Up, Down, Left, Right }
class Animal {
private name: string;
constructor(name: string) { this.name = name; }
}
05strictNullChecksTypeScript 2.0

null and undefined are no longer silently assignable to every type — eliminates an entire class of null-dereference bugs.

javascript
// With strictNullChecks: true
let name: string = null; // Error — null not assignable to string
let name: string | null = null; // OK — explicit
function greet(name: string | null) {
if (name !== null) {
name.toUpperCase(); // narrowed to string
}
}
06Non-null Assertion Operator (!)TypeScript 2.0

Tell the compiler a value is definitely non-null when it cannot verify it — a targeted escape hatch.

javascript
const input = document.getElementById('name')!; // asserts non-null
input.value = 'Alice'; // no "possibly null" error
const first = arr[0]!; // assert first element exists
07Control Flow Based Type AnalysisTypeScript 2.0

TypeScript follows every branch and assignment to narrow types at each point — the foundation of modern type narrowing.

javascript
function f(x: string | null) {
if (x === null) return; // eliminated null
x.toUpperCase(); // x: string — null was ruled out
}
08unknown TypeTypeScript 3.0

A type-safe alternative to any — values typed as unknown must be narrowed before use.

javascript
function process(value: unknown) {
// value.toUpperCase(); // Error — must narrow first
if (typeof value === 'string') {
value.toUpperCase(); // OK — narrowed to string
}
}
09Project ReferencesTypeScript 3.0

Split a TypeScript codebase into sub-projects that can reference each other, enabling incremental builds and better monorepo support.

javascript
// tsconfig.json
{
"references": [
{ "path": "./packages/core" },
{ "path": "./packages/ui" }
]
}
// tsc --build — builds only what changed
10Tuple Types with Rest ElementsTypeScript 3.0

Rest elements in tuple types enable precise typing of heterogeneous rest parameters and variadic generics.

javascript
type Strings = [string, ...string[]];
type Head<T extends unknown[]> = T extends [infer H, ...unknown[]] ? H : never;
type Tail<T extends unknown[]> = T extends [unknown, ...infer R] ? R : never;
11Optional Chaining & Nullish CoalescingTypeScript 3.7

TypeScript shipped ?. and ?? before they landed in the ECMAScript standard.

javascript
const city = user?.address?.city; // undefined if any part is null/undefined
const port = config.port ?? 3000; // default only for null/undefined (not 0 or '')
12Assertion FunctionsTypeScript 3.7

Functions annotated with asserts narrow the type for the caller after the call returns.

javascript
function assertIsString(val: unknown): asserts val is string {
if (typeof val !== 'string') throw new Error('Expected string');
}
let x: unknown = getValue();
assertIsString(x);
x.toUpperCase(); // x is string here — no error
13Recursive Type AliasesTypeScript 3.7

Type aliases can now directly reference themselves, enabling types like JSONValue without interface indirection.

javascript
type JSONValue =
| null | boolean | number | string
| JSONValue[]
| { [key: string]: JSONValue };
14Template Literal TypesTypeScript 4.1

Construct string literal types using template syntax — distributes over union members to produce every combination.

javascript
type Direction = 'top' | 'right' | 'bottom' | 'left';
type CSSMargin = `margin-${Direction}`;
// 'margin-top' | 'margin-right' | 'margin-bottom' | 'margin-left'
type EventName<T extends string> = `on${Capitalize<T>}`;
type ClickEvent = EventName<'click'>; // 'onClick'
15Key Remapping in Mapped TypesTypeScript 4.1

Remap keys in a mapped type using the as clause — enables renaming, filtering, and template-based transformations.

javascript
type Getters<T> = {
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K];
};
type PersonGetters = Getters<{ name: string; age: number }>;
// { getName: () => string; getAge: () => number }
16Recursive Conditional TypesTypeScript 4.1

Conditional types can now reference themselves, enabling deep unwrapping and recursive type transformations.

javascript
type DeepReadonly<T> = {
readonly [P in keyof T]: T[P] extends object ? DeepReadonly<T[P]> : T[P];
};
17satisfies OperatorTypeScript 4.9

Validates that a value matches a type while preserving the inferred literal type — get both validation and precision.

javascript
type Palette = Record<'red' | 'green' | 'blue', string | number[]>;
const palette = {
red: [255, 0, 0],
green: '#00ff00',
blue: [0, 0, 255],
} satisfies Palette;
palette.red.map(c => c / 255); // OK — red is number[], not string | number[]
18Auto-Accessor in ClassesTypeScript 4.9

The accessor keyword generates a private backing field with a getter/setter pair — designed for use with decorators.

javascript
class Person {
accessor name: string; // generates #name field + get/set name
constructor(name: string) { this.name = name; }
}
19Standard Decorators (TC39 Stage 3)TypeScript 5.0

Decorators now follow the TC39 Stage 3 proposal with a new API — class, method, field, accessor, getter/setter decorators.

javascript
function sealed(target: typeof MyClass, _ctx: ClassDecoratorContext) {
Object.seal(target);
Object.seal(target.prototype);
}
@sealed
class MyClass { name = 'TypeScript'; }
20const Type ParametersTypeScript 5.0

Generic functions with const modifier infer literal types instead of widened types, eliminating the need for as const at every call site.

javascript
function identity<const T>(value: T): T { return value; }
const a = identity(['a', 'b', 'c']);
// readonly ['a', 'b', 'c'] — not string[]
function defineRoutes<const T extends { path: string }[]>(routes: T): T {
return routes;
}
21All enums are Union enumsTypeScript 5.0

Enums are now treated as unions of their member types, enabling narrowing per member.

javascript
enum Status { Active = 'active', Inactive = 'inactive' }
function handle(s: Status) {
if (s === Status.Active) { /* narrowed to Status.Active */ }
}
22using & await using DeclarationsTypeScript 5.2

Explicit resource management via the Disposable interface — resources call [Symbol.dispose] automatically when they leave scope.

javascript
class DatabaseConnection implements Disposable {
[Symbol.dispose]() { this.close(); }
query(sql: string) { /* ... */ }
}
function runQuery() {
using db = new DatabaseConnection(); // auto-closed at block exit
return db.query('SELECT * FROM users');
} // db[Symbol.dispose]() called here
23Decorator MetadataTypeScript 5.2

Decorators can access context.metadata to attach and read metadata about the decorated class member.

javascript
function logged(_target: unknown, ctx: ClassMethodDecoratorContext) {
console.log(`Registering method: ${String(ctx.name)}`);
}
class Greeter {
@logged
greet(name: string) { return `Hello, ${name}`; }
}
24Inferred Type PredicatesTypeScript 5.5

TypeScript now infers return type predicates automatically from function bodies — filter(isString) finally returns string[].

javascript
function isString(x: unknown) {
return typeof x === 'string'; // inferred: x is string
}
const mixed: (string | number)[] = [1, 'hello', 2, 'world'];
const strings = mixed.filter(isString); // string[] — previously (string | number)[]
25Isolated DeclarationsTypeScript 5.5

New --isolatedDeclarations flag enforces explicit types on exports so .d.ts files can be generated without full type-checking — enables parallel DTS emit in monorepos.

javascript
// With isolatedDeclarations, public exports need explicit types
export function add(a: number, b: number): number { // explicit return type required
return a + b;
}
// export function add(a: number, b: number) { ... } // Error — inferred return
26Regular Expression Syntax CheckingTypeScript 5.5

TypeScript validates regex syntax and flags at compile time, catching typos in regex literals.

javascript
/(?<year>\d{4})-(?<month>\d{2})/; // OK — valid named groups
// /[a-z]/Z; // Error: Unknown flag 'Z'
// /(?!abc/; // Error: Unterminated group