Reusable type-safe components
| Command | Description |
|---|---|
function identity<T>(arg: T): T | Generic function declaration |
const box = <T>(val: T) => ({ val }) | Generic arrow function |
identity<string>("hello") | Explicit type argument |
| Command | Description |
|---|---|
interface Response<T> { data: T; error?: string } | Generic interface |
type Array<T> = T[] | Built-in generic |
| Command | Description |
|---|---|
<T extends { id: string }> | Must have id property |
keyof T | Union of keys of T |
T[K] | Access type of property K |