TypeScript Cheat Sheet
Practical TypeScript cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
typescript syntax examples reference
TypeScript cheat sheet with real commands and snippets for setup, core workflows, debugging, and production-safe automation patterns. If you are working across tools, pair this with the Angular Cheat Sheet and Bun Cheat Sheet.
Setup and Tooling
Goal: Install and verify language toolchain
# Run npm command
npm install -D typescript @types/node
# Run npx command
npx tsc --init
# Run npx command
npx tsc --version
Core Workflows
Goal: Run and build source code
# Execute npx workflow
npx tsc -p .
# Execute node workflow
node dist/index.js
Goal: Use a practical code snippet
// Generic helper that preserves input type
export function first<T>(items: T[]): T | undefined {
return items[0];
}
const value = first([1, 2, 3]);
Testing and Formatting
Goal: Run automated tests
# Execute test-related command
npx tsc --noEmit
# Execute test-related command
npm test
Goal: Run lint and formatter checks
# Execute quality command
npx eslint src --ext .ts,.tsx
# Execute quality command
npx prettier -w src
Automation and CI
Goal: Create a repeatable CI shell step
# Run strict shell mode for CI step
set -euo pipefail
# Install dependencies deterministically
npm ci || pip install -r requirements.txt || true
# Run tests and fail fast on errors
npx tsc --noEmit
Debugging and Troubleshooting
Goal: Trace runtime issues
# Print runtime and package manager versions
node --version || python --version || true
# Search stack traces and TODO markers
rg "Traceback|Exception|TODO" .
# Re-run tests with verbose output
npx tsc --noEmit -v || npx tsc --noEmit --verbose || true
Common Gotchas
- Pin TypeScript language/runtime versions in local and CI environments.
- Keep formatting and linting automated to avoid noisy diffs in code review.
- Prefer explicit dependency lock files for reproducible builds.
- Write small, deterministic tests that can run quickly in pre-commit checks.
- Document compiler/interpreter flags used in production builds.
Related Sheets
- Angular Cheat Sheet — daily Angular commands and production-ready examples.
- Bun Cheat Sheet — daily Bun commands and production-ready examples.
- Deno Cheat Sheet — daily Deno commands and production-ready examples.
Related Cheat Sheets
Angular Cheat Sheet
Practical Angular cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
Bun Cheat Sheet
Practical Bun cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.
Deno Cheat Sheet
Practical Deno cheat sheet with setup steps, core workflows, debugging, and copy-paste examples.