TypeScript

Peter Kröner, peter@peterkroener.de

Agenda

// _
const doThing = (x: Data): Result => ...

// _
class A extends B implements C {}

1.

„Premature type annotations are root of all evil.“

2.

Illustration: Kolja Wilcke

Zusammenfassung

// _
type A <T> = { foo: T };
// _
type A <T> = { foo: T };

// Mapped Types
type Readonly <T> = {
  readonly [K in keyof T]: T[K];
};
// _
type A <T> = { foo: T };

// Mapped Types
type Readonly <T> = {
  readonly [K in keyof T]: T[K];
};

// Conditional Types
type C = A extends B ? X : Y;
// _
type A <T> = { foo: T };

// Mapped Types
type Readonly <T> = {
  readonly [K in keyof T]: T[K];
};

// Conditional Types
type C = A extends B ? X : Y;

// _
type Entry <T extends Map <any, any>> =
  T extends Map <infer K, infer V>
    ? [ K, V ] : [ any, any ];