# Typescript Coding Standards

> TypeScript coding standards for the DR-NRPG platform. Loaded automatically when working on .ts/.tsx files. Covers types, async patterns, error handling, naming, and best practices.

- Skill: `cleanexpo/typescript-coding-standards` (Agent Skill)
- Install (CLI): `npx skillmds@latest add cleanexpo/typescript-coding-standards`
- Raw SKILL.md: https://api.skillmd.com/api/skills/cleanexpo/typescript-coding-standards/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: cleanexpo (https://skillmd.com/u/cleanexpo)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/cleanexpo/typescript-coding-standards

---


# TypeScript Coding Standards

## Core Rules
- TS strict mode. Zero `any`. Zero untyped exports.
- Explicit return types on all exported functions.
- Interfaces for object shapes. Type aliases for unions/intersections.
- Async/await over raw promises. Always try/catch with typed errors.
- Optional chaining (?.) and nullish coalescing (??) over manual null checks.
- Never use non-null assertion (!) unless justified with a comment.
- const by default. let only when value changes. Never var.
- Destructuring for cleaner code. Template literals for string interpolation.

## File Limits
- Functions: <40 lines. Extract if exceeding.
- Files: <300 lines. Split if exceeding.
- No dead code. No unused imports. No commented-out blocks.

## Naming
- Components: PascalCase (UserDashboard.tsx)
- Utilities: kebab-case (date-formatter.ts)
- Services: kebab-case (booking.service.ts)
- Types: kebab-case (user.types.ts)
- Tests: .test.ts or .spec.ts
- Constants: SCREAMING_SNAKE_CASE
- Enums: PascalCase with SCREAMING_SNAKE_CASE values

## Exports
- Named exports preferred over default exports.
- Barrel exports (index.ts) for module directories.
- JSDoc on every exported function.

## Error Handling
- Custom error classes: ValidationError, NotFoundError, UnauthorizedError, ConflictError
- Always log with context (userId, bookingId, etc.)
- Never expose internal errors to clients
- Consistent API response format: `{ success: boolean, data?: T, error?: { code, message } }`

