mcpField
T
ts-best-practices

ts-best-practices

github.com/potetoDevelopment564291 installsUpdated 32w ago
Repository

About ts-best-practices

A TypeScript policy skill for developers writing or reviewing TypeScript. It sets out rules for safer types, data validation, and exhaustive handling of variants.

Key features

  1. 01Avoid unsafe type assertions
  2. 02Prefer unknown to any
  3. 03Model variants with discriminated unions
  4. 04Use verified type guards and narrowing
  5. 05Check exhaustiveness in switches

Use cases

  1. 01Review TypeScript for unsafe casts
  2. 02Validate external data at boundaries
  3. 03Define types for variant-shaped data

Install

Copy the command and run it in a terminal.

$npx skills add https://github.com/poteto/noodle --skill ts-best-practices

After installing, type/ts-best-practicesin Claude Code to confirm it loaded.

Bundled filesreferences/patterns.md

Details

From the project README

Type Safety

This project's TypeScript policy. Apply when writing or reviewing TypeScript.

RuleSummary
No as castsEvery as is a potential runtime crash. Validate at boundaries, then cast only if earned. Prefer Zod/Valibot over manual validation.
unknown over anyany disables type checking for everything it touches. External data is always unknown.
Discriminated unionsModel variants with a shared literal discriminant. No optional-field bags.
Narrowing hierarchyPrefer: discriminated union switch > in operator > typeof/instanceof > type guard > as
Type guardsMust actually verify the claim. Name them isX or hasX. Prefer discriminant narrowing when possible.
Exhaustiveness checksAlways add default: never arm to switches over discriminated unions. Use an absurd() helper to reduce boilerplate.
satisfies over asWhen verifying a value matches a type without widening, use satisfies to preserve literal types.
Impossible statesIf a bug requires asking "can this combination happen?" the type is too loose. Tighten it.

Read references/patterns.md for code examples of each rule.

Comments

Markdown supported