.cursorrules — TypeScript (Universal)
Universal TypeScript rules for strict mode, proper error handling, and consistent naming conventions.
cursorrulestypescriptai-config
Prompt
You are a TypeScript expert. Apply strict TypeScript conventions to all code.
Type rules:
- strict mode enabled. No `any` — use `unknown` and narrow with type guards.
- Prefer interfaces for object shapes, types for unions/intersections.
- Use `import type {}` for type-only imports.
- Generics: meaningful names (TUser, not T) when more than one generic.
- Use `satisfies` for type-safe object literals: `const x = {...} satisfies Config`.
- Use `as const` for literal types: `const ROLES = ['admin', 'user'] as const`.
Function rules:
- Always type return values for exported functions.
- Use overloads for functions with different input/output type pairs.
- Prefer `readonly` parameters when the function doesn't mutate.
- Arrow functions for callbacks, named functions for top-level declarations.
Error handling:
- Use discriminated unions for results: { ok: true, data: T } | { ok: false, error: E }
- Type catch blocks: `catch (err: unknown)`, then narrow.
- Never ignore errors silently — handle or rethrow.
Naming:
- Interfaces: PascalCase, no "I" prefix (User, not IUser).
- Types: PascalCase (UserRole, ApiResponse).
- Enums: PascalCase members (Role.Admin, not Role.ADMIN).
- Constants: SCREAMING_SNAKE_CASE for true constants only.Why this prompt works
'No any — use unknown and narrow' is the single highest-impact TypeScript rule. AI tools default to any when types get complex; this rule forces correct solutions.
Save this prompt to your library
Organize, version, and access your best prompts across ChatGPT, Claude, and Cursor.
Related prompts
CLAUDE.md — Next.js + TypeScript + Tailwind
Production CLAUDE.md template for Next.js App Router projects with TypeScript strict mode and Tailwind CSS.
CLAUDE.md — Python + FastAPI + SQLAlchemyCLAUDE.md template for async FastAPI projects with SQLAlchemy 2.0, Alembic migrations, and pytest.
CLAUDE.md — Go + Chi Router + PostgreSQLCLAUDE.md template for Go APIs using Chi, pgx, and idiomatic Go project structure.
CLAUDE.md — React Native + ExpoCLAUDE.md template for React Native Expo projects with file-based routing, NativeWind, and Zustand.