agentleFS
andr-caandr-ca/agentharness/.claude/skills/typescript-conventions/SKILL.md

typescript-conventions

Skill1 starsChanged 2 months agoMITView on GitHub

Use when writing, reviewing, or refactoring TypeScript or JavaScript code — naming conventions, type annotations, private fields, null vs. undefined, async/await pitfalls, and module structure.

4 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • 0

    Common

    Most of the 4 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Prefer native # private fields (ES2022+/TS 3.8+) in new code — real runtime privacy, not a convention that's still readable via ["_name"].

    line 43
  2. Very specific:

    Don't rewrite working _prefix code on sight.

    line 45
  3. Very specific:

    Use vitest for Vite-based projects, jest for Node/Next.

    line 100

“Common” is measured: kept by at least 6 in 10 of the 4 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

TypeScript Conventions

This file is self-contained for day-to-day use. Deeper reference (needs the full harness checkout): languages/typescript/CONVENTIONS.md (full examples including generics and import grouping) and frameworks/react/CONVENTIONS.md (React/JSX-specific additions).

Naming

  • camelCase — functions, variables, method names. PascalCase — classes, interfaces, type aliases, enum names. UPPER_SNAKE_CASE — module-level constants.
  • Enum members: PascalCase.
  • Generic type params: T/U for simple one-liners; descriptive names (TEntity, TResponse) for complex or nested generics.

Imports & module structure

Group: external packages → internal modules → type-only imports. Separate each group with a blank line. Prefer import type for type-only imports (helps tools that strip types without full parsing).

import fs from 'fs';
import express from 'express';

import { UserRepository } from './repositories/UserRepository';

import type { User } from './types';

Private members: # over _prefix

Prefer native # private fields (ES2022+/TS 3.8+) in new code — real runtime privacy, not a convention that's still readable via ["_name"]. Don't rewrite working _prefix code on sight; it's not deprecated.

class TokenStore {
  #tokens: Map<string, string> = new Map();   // true runtime privacy
  #rotate(): void { /* ... */ }
}

Null vs. Undefined

Pick based on what absence means, then apply it consistently:

  • undefined (via ?) — "not provided / not yet set."
  • null — an explicit "no value" the code sets deliberately (nullable column, "user cleared this field").
  • Do not mix both for the same kind of absence in one module.

Pitfalls to catch in review

// WRONG: async function catches error, logs it, then resolves — hides failure
async function save(data: Data): Promise<void> {
  try {
    await db.write(data);
  } catch (err) {
    logger.error('save failed', err);
    // caller sees a successful promise despite the failure
  }
}

// RIGHT: rethrow after logging so the caller can handle the failure
async function save(data: Data): Promise<void> {
  try {
    await db.write(data);
  } catch (err) {
    logger.error('save failed', err);
    throw err;  // caller knows this failed
  }
}

// Type-cast escape hatch silences the compiler, not the bug
const result = someValue as SomeType;  // risky without a runtime check
// Prefer a type guard:
function isSomeType(v: unknown): v is SomeType { /* ... */ }

// Non-null assertion hides null/undefined bugs
const name = user!.profile!.name;   // crashes at runtime if null
// RIGHT: optional chaining + fallback
const name = user?.profile?.name ?? 'Unknown';

Testing

tests/ or __tests__/ directories, *.test.ts / *.spec.ts files. Use vitest for Vite-based projects, jest for Node/Next. See patterns/testing/TDD.md for the broader methodology — this skill covers TypeScript-specific structure only.

Formatting & tooling

Defer to the project's tsconfig.json and eslint.config.* — don't impose defaults over an existing configured setup. If unconfigured: strict: true in tsconfig, prettier for formatting (2-space indent, single quotes), eslint with @typescript-eslint/recommended.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.