agentleFS
Baba01hacker666Baba01hacker666/dummyskills/skills/typescript/ts-code-quality/SKILL.md

ts-code-quality

Skill0 starsChanged 2 months agoMITView on GitHub

Guides agents in applying idiomatic TypeScript architecture: discriminating unions, readonly immutability, branded types, and zero any.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

Show its rules and text

We split this skill into the rules it gives an agent

13 rules. About 0 are common, 5 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈5

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this skill when:

    line 14
  2. Very specific:

    Do not use to run unit tests.

    line 20
  3. Very specific:

    Do not use to fix immediate syntax compiler errors.

    line 21
  4. Distinctive:

    If no goal is specified: review the file against standard TypeScript code quality invariants.

    line 28
  5. Distinctive:

    Never introduce runtime overhead or change public function behavior.

    line 29
  6. Distinctive:

    Follow these numbered actions:

    line 32
  7. Very specific:

    Search for any, non-null assertions (!), and conflicting booleans.

    line 34
  8. Very specific:

    Add readonly to interface properties and ReadonlyArray<T> to prevented accidental mutation.

    line 38
  9. Very specific:

    Use assertNever(value: never) in default branches.

    line 40
  10. Very specific:

    Run npx tsc --noEmit and npm test.

    line 42
  11. Very specific:

    If an array is passed as parameter and not mutated: type as readonly T[].

    line 45
  12. Very specific:

    If an object is configuration data: use as const assertion.

    line 46
  13. Distinctive:

    Stop and ask the user when:

    line 75

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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 Code Quality & Idioms

Enforces high-standard TypeScript practices: discriminating unions over loose booleans, readonly immutability, unknown over any, and exhaustive pattern matching.

1. Purpose

Elevate TypeScript code quality and maintainability. A "Discriminating Union" uses a literal tag (e.g. type: 'success' | 'error') to guarantee complete type narrowing at compile time.

2. When to Use

Use this skill when:

  • Designing API response types, domain models, or state reducers.
  • Refactoring complex state objects with multiple conflicting boolean flags (isLoading, isError, isSuccess).
  • Removing legacy any types and replacing with safe generic or unknown types.

3. When Not to Use

  • Do not use to run unit tests; use ts-testing.
  • Do not use to fix immediate syntax compiler errors; use ts-lint-and-typecheck.

4. Required Inputs

  • target_file: Path to the TypeScript file to review or improve.
  • improvement_goal: Architectural improvement (e.g. "Model state as discriminating union").

5. Missing-Input Behavior

  1. If no goal is specified: review the file against standard TypeScript code quality invariants.
  2. Never introduce runtime overhead or change public function behavior.

6. Procedure

Follow these numbered actions:

  1. Action 1: Audit for Anti-Patterns
    • Search for any, non-null assertions (!), and conflicting booleans.
  2. Action 2: Apply Discriminating Unions
    • Replace conflicting boolean flags with single tagged unions.
  3. Action 3: Apply Immutability
    • Add readonly to interface properties and ReadonlyArray<T> to prevented accidental mutation.
  4. Action 4: Add Exhaustive Switch Checks
    • Use assertNever(value: never) in default branches.
  5. Action 5: Verify Type-Check and Tests
    • Run npx tsc --noEmit and npm test.

7. Decision Rules

  • If an array is passed as parameter and not mutated: type as readonly T[].
  • If an object is configuration data: use as const assertion.

8. Output Format

Emit the report using this template:

### TypeScript Code Quality Report: [Target File]

- **File Modified**: `[path]`
- **Patterns Applied**: [e.g., Discriminating Unions, Readonly Immutability]
- **Type-Check Status**: PASS
- **Test Status**: PASS

#### Improvements Made
- [Improvement 1 with rationale]
- [Improvement 2 with rationale]

9. Verification Checklist

  • Zero any types remain in modified code.
  • Discriminating unions replace loose boolean states.
  • tsc --noEmit passes cleanly.
  • Existing tests pass without regression.

10. Common Failures and Recovery

Failure SymptomCauseRecovery Action
Missing case in unionAdding new union memberAdd default: assertNever(x) to catch unhandled cases at compile time.

11. Stop or Escalation Conditions

Stop and ask the user when:

  • Proposed refactor breaks database serialization formats.

12. Examples

Example 1: Successful Execution

Input:

File: src/state.ts
Issue: State has { isLoading: boolean, error?: string, data?: User }
Goal: Convert to Discriminating Union

Output:

### TypeScript Code Quality Report: src/state.ts

- **File Modified**: `src/state.ts`
- **Patterns Applied**: Discriminating Unions
- **Type-Check Status**: PASS
- **Test Status**: PASS

#### Improvements Made
- Replaced 3 optional properties with typed union:
  ```typescript
  type AsyncState<T> =
    | { status: 'idle' }
    | { status: 'loading' }
    | { status: 'success'; data: T }
    | { status: 'error'; error: Error };
  • Eliminates impossible states (e.g. isLoading: true with data defined).

### Example 2: Ambiguous or Missing Input
**Input:**
```text
Make my TS better.

Output:

### TypeScript Code Quality Report: Halted - Missing File

- **Status**: Halted

Please specify the TypeScript file you would like to improve.

Example 3: Expected Final Output

Output:

### TypeScript Code Quality Report: src/options.ts

- **File Modified**: `src/options.ts`
- **Patterns Applied**: Readonly Immutability & `as const`
- **Type-Check Status**: PASS
- **Test Status**: PASS

#### Improvements Made
- Added `readonly` modifier to configuration options interface.

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.