Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use this skill when working in a strict TypeScript codebase and you want reliable patterns for modeling data, narrowing, generics, and configuration—without papering over errors with `as` casts.
.claude/skills/amariahak-typescript-patterns/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-05 | ✗→✓ | ▲ Improved | -13% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 85% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 121% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 112% | 0% |
| case-04 | ✓→✓ | = Same ✓ | 57% | 0% |
Use this skill when working in a strict TypeScript codebase and you want reliable patterns for modeling data, narrowing, generics, and configuration—without papering over errors with as casts.
Prefer strict: true and keep these on unless you have a strong reason:
noUncheckedIndexedAccessexactOptionalPropertyTypesnoImplicitOverride (when using classes)Treat any relaxation as a conscious decision with a documented reason.
unknown over anyUse unknown at boundaries:
Then narrow:
tsfunction isRecord(x: unknown): x is Record<string, unknown> { return typeof x === "object" && x !== null; }
Use the built-in primitives:
typeof for primitivesinstanceof for classes/errors"in" for structural checkststype Result = | { ok: true; value: string } | { ok: false; error: string }; function handle(r: Result) { if (!r.ok) return r.error; return r.value; }
Avoid boolean soup (isLoading, hasError, isEmpty …). Prefer:
tstype LoadState = | { kind: "idle" } | { kind: "loading" } | { kind: "error"; message: string } | { kind: "ready"; items: string[] };
Useful:
Pick, Omit for DTO shapingReturnType, Parameters for typed wrappersPartial only for “patch” objects (not for real domain models)Anti-pattern:
Partial<Model> to “get around” missing required fieldssatisfies > type assertionsPrefer:
tsconst routes = { home: "/", settings: "/settings", } satisfies Record<string, string>;
Avoid:
as Record<string, string> (it can lie)as const for literal preservationUse as const to keep literals and readonly tuples:
tsconst roles = ["admin", "user"] as const; type Role = (typeof roles)[number];
Add generics when:
Stop adding generics when:
Good generic:
tsexport function groupBy<T, K extends string | number>( items: T[], key: (item: T) => K, ): Record<K, T[]> { return items.reduce((acc, item) => { const k = key(item); (acc[k] ??= []).push(item); return acc; }, {} as Record<K, T[]>); }
as casts (make invalid states unrepresentable)Prefer:
never to enforce exhaustivenesstsfunction assertNever(x: never): never { throw new Error("Unexpected: " + String(x)); }
Recommended baseline:
strict: trueskipLibCheck: true (usually OK)noEmit: true in typecheck scriptsmoduleResolution aligned with your runtime/bundlerIf using ESM:
grep/glob to find any/unknown boundaries, and track how a value flows through modules.any for convenience instead of writing a small guardPartial<T> as a general-purpose escape hatchas casts instead of validating onceunknown → narrowed)switch/if for key unions| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 5,852 | 3,565 | -39% | 1 | 1 | 0% | 945 | 1,750 | +85% | 0 | 0 | — |
case-02 | pass→pass | 4,410 | 4,313 | -2% | 1 | 1 | 0% | 830 | 1,835 | +121% | 0 | 0 | — |
case-03 | pass→pass | 4,311 | 3,106 | -28% | 1 | 1 | 0% | 762 | 1,618 | +112% | 0 | 0 | — |
case-04 | pass→pass | 9,870 | 9,072 | -8% | 1 | 1 | 0% | 1,797 | 2,817 | +57% | 0 | 0 | — |
case-05 | fail→pass | 14,500 | 6,213 | -57% | 1 | 1 | 0% | 2,614 | 2,274 | -13% | 0 | 0 | — |
case-06 | pass→pass | 3,648 | 3,701 | +1% | 1 | 1 | 0% | 710 | 1,622 | +128% | 0 | 0 | — |
case-07 | pass→pass | 7,981 | 4,119 | -48% | 1 | 1 | 0% | 1,432 | 1,869 | +31% | 0 | 0 | — |
case-08 | pass→pass | 8,837 | 7,090 | -20% | 1 | 1 | 0% | 1,627 | 2,099 | +29% | 0 | 0 | — |
case-09 | pass→pass | 7,209 | 4,935 | -32% | 1 | 1 | 0% | 1,403 | 2,078 | +48% | 0 | 0 | — |
case-10 | pass→pass | 5,254 | 3,142 | -40% | 1 | 1 | 0% | 1,051 | 1,661 | +58% | 0 | 0 | — |
case-11 | pass→pass | 9,746 | 5,721 | -41% | 1 | 1 | 0% | 1,782 | 2,134 | +20% | 0 | 0 | — |
case-12 | pass→pass | 14,132 | 9,332 | -34% | 1 | 1 | 0% | 2,640 | 2,792 | +6% | 0 | 0 | — |
case-13 | pass→pass | 6,184 | 5,259 | -15% | 1 | 1 | 0% | 1,038 | 1,940 | +87% | 0 | 0 | — |
case-14 | pass→pass | 4,049 | 3,564 | -12% | 1 | 1 | 0% | 703 | 1,732 | +146% | 0 | 0 | — |
case-15 | pass→pass | 5,352 | 3,313 | -38% | 1 | 1 | 0% | 1,029 | 1,735 | +69% | 0 | 0 | — |
case-16 | pass→pass | 13,660 | 7,397 | -46% | 1 | 1 | 0% | 1,649 | 2,454 | +49% | 0 | 0 | — |
case-17 | pass→pass | 3,921 | 3,245 | -17% | 1 | 1 | 0% | 600 | 1,617 | +170% | 0 | 0 | — |
case-18 | pass→pass | 7,298 | 4,918 | -33% | 1 | 1 | 0% | 1,431 | 1,993 | +39% | 0 | 0 | — |
case-19 | fail→fail | 10,039 | 7,403 | -26% | 1 | 1 | 0% | 1,780 | 2,484 | +40% | 0 | 0 | — |
case-20 | pass→pass | 6,135 | 5,300 | -14% | 1 | 1 | 0% | 1,208 | 2,099 | +74% | 0 | 0 | — |
case-21 | pass→pass | 8,178 | 8,665 | +6% | 1 | 1 | 0% | 1,615 | 2,828 | +75% | 0 | 0 | — |
case-22 | pass→pass | 7,911 | 3,312 | -58% | 1 | 1 | 0% | 1,146 | 1,656 | +45% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +5 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.