Skills Development TypeScript Best Practices

TypeScript Best Practices

v20260407
typescript-best-practices
Enforces modern TypeScript patterns during development and reviews, guiding const usage, explicit return types, interface-driven shapes, and avoiding any/var or ignored errors.
Get Skill
100 downloads
Overview

TypeScript Best Practices

When to Use

Use this skill when:

  • Writing new TypeScript code
  • Reviewing TypeScript pull requests
  • Refactoring JavaScript to TypeScript

Triggers

Activated when editing .ts or .tsx files in the project.

Rules

Always

  • Always use const for variables that won't be reassigned
  • Always use explicit return types on exported functions
  • Always prefer interface over type for object shapes

Never

  • Never use any — use unknown instead
  • Never use var — use const or let
  • Never ignore TypeScript errors with @ts-ignore

Examples

// Good: explicit return type
export function calculateTotal(items: Item[]): number {
  return items.reduce((sum, item) => sum + item.price, 0);
}
// Good: discriminated union
type Result<T> =
  | { success: true; data: T }
  | { success: false; error: Error };

Boundaries

  • Do not modify tsconfig.json without explicit permission
  • Do not add new dependencies without checking existing utilities
  • Focus only on TypeScript patterns, not runtime behavior
Info
Category Development
Name typescript-best-practices
Version v20260407
Size 1.28KB
Updated At 2026-04-14
Language