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.
| 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 static files are identical to what the API returns, but with no rate limit and no server round trip. Use the API when you want a query and a content type; use the files when you want to cache one document.
curl "https://yjtoon.com/api/dataset/typescript-type-system?format=toon"
const res = await fetch( "https://yjtoon.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 →