typescript · v1.0 · 2026-07-20 · sha256 c0d7004a254ffd09
typescript v1.0A
Immutable. This exact content never changes and is served at /api/v1/blob/c0d7004a254ffd09.
---
name: typescript
description: Typed JavaScript.
license: MIT
metadata:
author: vant
version: "1.0"
---
# TypeScript
> Typed JavaScript.
---
## When To Use
- Type safety needed
- Large codebases
- Modern JS projects
---
## What To Do
### 1. Types
```typescript
interface User {
id: number
name: string
email?: string // optional
}
function getUser(id: number): User {
return { id, name: 'User' }
}
```
### 2. Generics
```typescript
function first<T>(arr: T[]): T {
return arr[0]
}
```
### 3. Compile
```bash
npx tsc --init
npx tsc
npx tsc --watch
```
### 4. Config
```json
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"strict": true
}
}
```
---
**Role**: TypeScript Developer
**Input**: .ts files
**Output**: .js files
> Typed JS.