TypeScript Type System
TypeScript's static type system: types, interfaces, generics, utility types, and advanced type manipulation.
TypeScript's static type system: types, interfaces, generics, utility types, and advanced type manipulation.
The TypeScript type system's main concepts, from primitive types, interfaces and generics to union and intersection types, type guards, utility types, discriminated unions, mapped and conditional types and template literal types, each with a description and example.
| Name | Types | Description | Example | Keyword | Patterns | Common | Pattern |
|---|---|---|---|---|---|---|---|
| Primitive Types |
| Basic built-in types. TypeScript adds `any`, `unknown`, `never`, `void`. | let name: string = "Alice"; let age: number = 30; let isActive: boolean = true; | null | null | null | null |
| Interfaces | null | Define object shape; can be extended and implemented. Structural typing. | interface User { id: number; name: string; email?: string; } const u: User = { id: 1, name: "Bob" }; | interface | null | null | null |
| Type Aliases | null | Create new named type; can represent primitives, unions, tuples, objects. | type ID = number | string; type Point = [number, number]; type User = { name: string }; | type | null | null | null |
| Generics | null | Type variables enable reusable components that work with multiple types. | function identity<T>(arg: T): T { return arg; } let output = identity<string>("hello"); | <T> | null | null | null |
| Union Types | null | Value can be one of several types; use type guards to narrow. | function format(x: string | number) { if (typeof x === 'string') { ... } else { ... } } | | | null | null | null |
| Intersection Types | null | Combine multiple types into one; object must satisfy all constraints. | type Admin = User & { permissions: string[] }; | & | null | null | null |
| Type Guards | null | Narrow types within conditional blocks. | function isString(x: unknown): x is string { return typeof x === 'string'; } if (isString(val)) { val.toUpperCase(); } | null |
| null | null |
| Utility Types | null | Built-in type transformations; avoid manual re-declaration. | interface Post { title: string; content: string; published: boolean; } type EditPost = Pick<Post, 'title' | 'content'>; | null | null |
| null |
| Discriminated Unions | null | Union of types with common literal field; enables exhaustive type checking in switch. | type Shape = { kind: 'circle'; radius: number } | { kind: 'square'; side: number }; function area(s: Shape) { switch(s.kind) { case 'circle': return Math.PI * s.radius ** 2; ... } } | null | null | null | tagged union |
| Mapped Types | null | Create types by mapping over properties of another type. | type Readonly<T> = { readonly [P in keyof T]: T[P]; } type Optional<T> = { [P in keyof T]?: T[P] }; | keyof, in | null | null | null |
| Conditional Types | null | Types that choose between two types based on a condition. | type IsString<T> = T extends string ? true : false; type NonNullable<T> = T extends null | undefined ? never : T; | T extends U ? X : Y | null | null | null |
| Template Literal Types | null | Build strings from other types; useful for CSS property names, API endpoints. | type EventName = `on${Capitalize<string>}`; // onLoad, onMouseEnter, etc. | `${}` | null | null | null |
The shape of this dataset, read from the data itself: every column, its type and a real value. Agents can use this to plan a query without fetching the whole document.
| Section | Field | Type | Example |
|---|---|---|---|
| concepts | name | string | Primitive Types |
| concepts | types | array | [7 items] |
| concepts | description | string | Basic built-in types. TypeScript adds `any`, `u… |
| concepts | example | string | let name: string = "Alice"; let age: number = 3… |
| concepts | keyword | string | interface |
| concepts | patterns | array | [4 items] |
| concepts | common | array | [6 items] |
| concepts | pattern | string | tagged union |
The static files contain the same reference rows as the API, with no API rate limit. Live metadata, such as view counts, may differ. Use the API for content negotiation; use the static files for a cacheable snapshot.
curl "https://yjtoon.yunusemrevurgun.com/api/dataset/typescript-type-system?format=toon"
const res = await fetch( "https://yjtoon.yunusemrevurgun.com/static-data/dataset/typescript-type-system.toon" ); const toon = await res.text();
Rate limit: 120 requests per minute per IP, no key and no signup. API reference →