CommunityProgramación y desarrollogithub.com

clean-typescript

Write readable, maintainable TypeScript without type assertions, inline functions, or arrow function variable assignments.

¿Qué es clean-typescript?

clean-typescript is a Claude Code agent skill that write readable, maintainable TypeScript without type assertions, inline functions, or arrow function variable assignments.

Compatible con~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mnboos/skills/tree/HEAD/clean-typescript

Installed? Explore more Programación y desarrollo skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

Preguntar en tu IA favorita

Abre un nuevo chat con esta habilidad de agente ya precargada.

Documentación

Clean TypeScript Guidelines

Follow these rules when writing or reviewing TypeScript code.

1. Type Safety

  • No type casts or assertions: Never use as Type, <Type>value, or the non-null assertion operator (!). These bypass the compiler and defeat static typing.
  • No any: Use unknown for values whose shape is not yet verified, then narrow them before use.
  • Use type guards and narrowing: Write user-defined type guards (value is Type), or use in checks, typeof, instanceof, and discriminated unions so the compiler proves types naturally.
  • Validate at boundaries: Parse external inputs (JSON responses, environment variables, form data) with runtime checks or schema validators at the system boundary.
  • Prefer string union types over enum: Use type Status = "open" | "closed" instead of enum for simpler runtime behavior and cleaner narrowing.
  • Exceptions: Only use a type assertion when interfacing with a broken third-party type definition where no runtime check is possible. Isolate the assertion inside a single small helper function and add a comment explaining why it cannot be avoided.
// Avoid
function getUserName(data: unknown): string {
  return (data as { name: string }).name;
}

// Prefer
function isUserRecord(value: unknown): value is { name: string } {
  return typeof value === "object" && value !== null && "name" in value && typeof value.name === "string";
}

function getUserName(data: unknown): string {
  if (!isUserRecord(data)) {
    throw new Error("Invalid user record");
  }
  return data.name;
}

2. Functions

  • Use function declarations: Always use the function keyword for named functions instead of assigning arrow functions to const variables.
  • Avoid inline functions: Do not pass multi-line or complex inline callbacks to methods like .map(), .filter(), .reduce(), or event listeners. Extract them into named function declarations.
  • When inline functions are acceptable: Short, single-expression callbacks that depend directly on local closure variables (such as items.filter((item) => item.groupId === currentGroupId)) are acceptable when extracting them would obscure intent. Otherwise, pass a named function reference (such as items.filter(isActive)).
// Avoid
const getActiveUserEmails = (users: User[]): string[] => {
  return users
    .filter((user) => {
      return user.isActive && !user.isSuspended;
    })
    .map((user) => user.email);
};

// Prefer
function isEligibleUser(user: User): boolean {
  return user.isActive && !user.isSuspended;
}

function getUserEmail(user: User): string {
  return user.email;
}

function getActiveUserEmails(users: User[]): string[] {
  return users.filter(isEligibleUser).map(getUserEmail);
}

3. File and Module Structure

  • Balanced granularity: Group related types, constants, and functions into cohesive modules organized by feature or domain.
  • Avoid extremes:
    • Do not put the entire application into one giant file.
    • Do not create a separate file for every tiny function or single-property type.
  • Practical boundaries:
    • Split a file when it handles more than one distinct responsibility or grows past roughly 200–300 lines.
    • Merge files that contain only 10–20 lines and are always imported together by the same caller.
  • Explicit exports: Export only the public API of each module. Keep internal helper functions unexported at the bottom of the file.

4. Readability and Naming

  • Keep code readable: Favor clear, step-by-step logic over clever one-liners, nested ternaries, or dense method chains. Assign intermediate steps to named variables.
  • Use plain words: Name variables, functions, types, and files with simple, everyday words that describe what they hold or do.
  • Avoid unnecessary adjectives: Do not use vague, promotional, or filler adjectives in names, comments, or documentation (avoid words like smart, fast, simple, advanced, clean, helper, or manager). Only use an adjective when it states a concrete domain fact (such as activeUsers or emptyCart).

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Skills relacionados