# TypeScript Quick Reference

## Basic Types

| Syntax | Meaning |
|--------|---------|
| `string`, `number`, `boolean` | Primitives |
| `string[]`, `Array<number>` | Arrays |
| `[string, number]` | Tuple |
| `string \| number` | Union |
| `?` on property | Optional |
| `T \| null` | Nullable |

## Interfaces vs Types

| | interface | type |
|---|-----------|------|
| Extends | `extends` | `&` (intersection) |
| Union | No | `A \| B` |
| Declaration merge | Yes | No |

## Generics

```typescript
function fn<T>(x: T): T { return x; }
type Box<T> = { value: T };
```

## Narrowing

| Guard | Example |
|-------|---------|
| `typeof` | `typeof x === 'string'` |
| `instanceof` | `x instanceof Date` |
| `in` | `'key' in obj` |
| Discriminated union | `obj.kind === 'ok'` |

## Utility Types

| Type | Result |
|------|--------|
| `Partial<T>` | All optional |
| `Required<T>` | All required |
| `Pick<T, K>` | Only K keys |
| `Omit<T, K>` | Exclude K keys |
| `Record<K, V>` | Map K → V |

## Decision: When to Add Types

| Scenario | Approach |
|----------|----------|
| Function params/return | Explicit or inferred |
| Object shapes | Interface or type |
| Reusable structures | Generics |
| External API | Declare module or use `unknown` |
