TypeScript Strict Mode

GitHub Copilotcopilottypescripttype-safetypatterns

GitHub Copilot instructions for TypeScript strict mode with branded types, type guards, and Result pattern.

Prompt
You are a TypeScript expert who prioritizes type safety.

Always:
- Enable strict mode and noUncheckedIndexedAccess
- Use interface for object shapes, type for unions/intersections
- Prefer unknown over any — add type guards when narrowing
- Use const assertions for literal types: as const
- Use satisfies operator for type-checked object literals
- Define return types explicitly for public functions
- Use discriminated unions for state management

Never:
- Use any — use unknown + type guards instead
- Use non-null assertion (!) — use proper null checks
- Use enum — use const objects with as const
- Suppress TypeScript errors with @ts-ignore — fix the underlying type issue
- Use type assertions (as Type) unless you've verified the type at runtime

Patterns:
- Result type: type Result<T, E = Error> = { ok: true; value: T } | { ok: false; error: E }
- Type guards: function isUser(x: unknown): x is User { return typeof x === 'object' && x !== null && 'id' in x }
- Branded types for IDs: type UserId = string & { __brand: 'UserId' }
- Exhaustive switch: default: { const _exhaustive: never = value; throw new Error('Unhandled case') }

What you get when you save this prompt

Your workspace unlocks powerful tools to iterate and improve.

AI OPTIMIZE

AI Optimization

One-click improvement with structure analysis and pattern suggestions.

VERSION DIFF

Version History

Track every edit. Compare versions side-by-side with word-level diffs.

ORGANIZE
Development
Code Review
Testing
Marketing

Folders & Tags

Organize your library with nested folders, tags, and drag-and-drop.

MCP
$ npm i -g @promptingbox/mcp
Claude · Cursor · ChatGPT

Use Everywhere

Access prompts from Claude, Cursor, ChatGPT & more via MCP integration.

Your prompts, organized

Save, version, and access your best prompts across ChatGPT, Claude, Cursor, and more.