Use when authoring or converting TypeScript — defining a type / interface / function signature, typing arguments or state, deciding between optional fields and a union, or about to reach for any, unknown, Record<string, unknown>, an index signature, or an as cast. The minimum modeling rules for making code TypeScript.
Ships in typescript-modeling. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A type must model reality exactly: every argument and every state, with no looser shape than the truth. any, bare unknown, Record<string, unknown>, open index signatures, and as are where models go to die — they each say "I gave up modeling here." When you make code TypeScript, the goal is not "it compiles" but "impossible states are unrepresentable."
any. Ban Record<string, unknown> / [k: string]: unknown for "arbitrary" or "pass-through" data — "arbitrary" almost always means "I didn't enumerate it yet." Enumerate the fields, or model the variants as a union of concrete shapes.unknown only at a true external boundary, and only in transit. Network/JSON/process.env may arrive as unknown — immediately parse it into a concrete type (zod .parse, a type guard). unknown must never be a field type, a return type, or a resting place; it is a doorway, not a room.type/kind/outcome) carrying only that state's data. The compiler then makes illegal field access (reading success data off a failure) impossible, and switch exhaustiveness flags missing states.?: fields. Many optionals on one interface = you merged several states into one shape and pushed the distinction onto the reader. Reserve ?: for a field that is genuinely, independently absent (e.g. description?), not for state.satisfies over as. as silences the checker and can lie; satisfies checks the value against the type AND keeps its narrow inferred type. Annotate literals with satisfies, never as. Use as only for narrowing the checker genuinely cannot express — and prefer a type guard even then.// ❌ every field optional; nothing stops `result.session` on a failure
interface AuthResult {
ok: boolean;
user?: User; session?: Session; // success only
code?: string; status?: number; // failure only
challengeId?: string; methods?: AuthMethod[]; // mfa only
}
// ✅ the union names each state; each variant carries ONLY its own data
type AuthResult =
| { outcome: 'success'; user: User; session: Session }
| { outcome: 'failure'; code: string; status: number }
| { outcome: 'mfa_required'; challengeId: string; methods: AuthMethod[] };
const summarize = (r: AuthResult): string => {
switch (r.outcome) {
case 'success': return `signed in as ${r.user.name}`;
case 'failure': return `failed (${r.code}, ${r.status})`;
case 'mfa_required': return `mfa: ${r.methods.join(', ')}`;
// add a 4th outcome → this switch fails to compile until handled
}
};
// ❌ the index signature is a giveaway: the flags were never modeled
interface AuthOptions {
clientIp?: string;
requireDatabase?: boolean;
[featureFlag: string]: unknown; // "callers can pass anything"
}
// ✅ name the flags; a new flag is a one-line type change, reviewable & autocompleted
interface FeatureFlags {
betaPasskeyFlow: boolean;
rolloutBucket: number;
}
interface AuthOptions {
clientIp?: string;
requireDatabase?: boolean;
flags: FeatureFlags;
}
satisfies, not annotation-or-as (rule 5)const opts = { clientIp: '203.0.113.7', requireDatabase: true } as AuthOptions; // ❌ as: can hide missing/extra fields
const opts: AuthOptions = { clientIp: '203.0.113.7', requireDatabase: true }; // ❌ widens literals, drops inference
const opts = { clientIp: '203.0.113.7', requireDatabase: true } satisfies AuthOptions; // ✅ checks AND keeps narrow types
| You're about to write | Do instead |
|---|---|
any | model it; if truly external, unknown + parse |
Record<string, unknown> / [k: string]: unknown | enumerate fields, or a union of concrete shapes |
unknown as a field/return type | parse at the boundary into a concrete type first |
interface with many ?: fields | split into a discriminated union by state |
boolean flags + optional payload | one variant per state, payload non-optional inside it |
x as T | x satisfies T; or a type guard (x): x is T |
value as any to "make it work" | fix the model; as any is never the answer |
| Excuse | Reality |
|---|---|
| "The flags are arbitrary, I need an index signature" | "Arbitrary" = unenumerated. List them; add a field when a flag is born. |
| "Optionals are simpler than a union" | They push every "is this set?" check onto every reader, forever. The union checks once. |
"as is fine, I know the shape" | Then satisfies proves it for free. as only matters when you might be wrong — exactly when it's dangerous. |
"unknown is the safe version of any" | Only if narrowed immediately. As a resting type it's any with extra steps. |
| "I'll model it properly later" | The optional-soup interface is the thing you ship and never revisit. Model it now. |
Record<string, unknown>, [k: string]: unknown, or any for "config"/"options"/"metadata"/"payload".?:.as on anything other than narrowing the checker provably can't do.boolean/status field that decides which other fields are meaningful — that's a discriminant; make it a union.What SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
8 skills in this plugin
/branching-modeled-state-with-switchUse when writing TypeScript that branches on a value carrying a modeled state — a discriminated union, a status/kind/type tag, or any state-machine state — to choose behavior or a return value, or when adding a variant to such a union. Also when reaching for an if/else-if chain, an assertNever helper, or a lookup map to consume a tagged union./chaining-neverthrow-resultsUse when composing or chaining neverthrow Result / ResultAsync values — sequencing multi-step operations where each step can fail, recovering from a specific error, or deciding where to turn a Result into a plain value or HTTP response. Also when reaching for .match mid-pipeline, _unsafeUnwrap, isErr()+.value unwrapping, safeTry / yield*, or a try/catch around Result-returning code./explicit-primitive-conversionUse when converting a value to a number, string, or boolean in TypeScript, or annotating a primitive type — about to write Number(x), Number.parseInt, Number.parseFloat, String(x), Boolean(x), unary +x, !!x, .filter(Boolean), .map(Number), or a : Number / : String / : Boolean type annotation./modeling-errors-as-classesUse when defining an error type, an error channel for a Result/ResultAsync, or a failure that crosses a throw / Promise rejection / serialization boundary — anything you would otherwise model as an object union like `{ name: 'XError'; message: string }`./prefix-match-processorUse when branching keys off the prefix of a string (startsWith, namespaced name families like "file.", "edit.", "edit.image.") and the number of prefix branches is growing, when a prefix if-chain is becoming hard to test or extend per-family, or when adding several new prefix families to an existing dispatcher./switch-patternConvert `if`-based discriminated-value matching (HTTP status codes, event/action `type` fields, mode strings) to exhaustive `switch` statements. Use when refactoring existing code to the project style or when reviewing a file for `if (x === ...) / if (x !== ...)` clusters that should be flattened to switch.
/typescript-modeling:precise-type-modelingfrom typescript-modeling
npx claudepluginhub naporin0624/astro-agent-starter --plugin typescript-modeling