From TypeScript Expert
Expert TypeScript: type system, generics, narrowing, inference, and strict-mode safety. Trigger keywords: TypeScript, types, generics, type narrowing, tsconfig, strict, discriminated union, conditional/mapped types, utility types, declaration files, type error, satisfies, infer, any vs unknown. Use when writing/refactoring TS, fixing cryptic type errors, designing type-safe/generic APIs, or configuring the compiler.
How this skill is triggered — by the user, by Claude, or both
Slash command
/typescript-expert:typescript-expertThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
> Make illegal states unrepresentable. Let inference do the work; annotate boundaries, not internals. `any` is a hole in the type system — reach for `unknown` + narrowing instead.
Make illegal states unrepresentable. Let inference do the work; annotate boundaries, not internals.
anyis a hole in the type system — reach forunknown+ narrowing instead.
not assignable, excessively deep, variance complaints).tsconfig.json, writing .d.ts, or migrating JS → TS.react-expert.nodejs-backend-expert.strict: true is the floor. Add noUncheckedIndexedAccess (array access is T | undefined), and for libraries exactOptionalPropertyTypes + noImplicitOverride.strict to "make it compile" — the error is usually a real bug. Fix the model.any vs unknownany disables checking and silently spreads. Ban it (@typescript-eslint/no-explicit-any).catch, 3rd-party) use unknown, then narrow with a guard or schema (zod) before use.as const for literal tuples/objects, and satisfies to validate a value against a type without widening it (keeps the precise inferred type).kind/status field unlocks exhaustive narrowing.ReturnType, Parameters, Awaited, keyof, indexed access (T["field"]), Pick/Omit/Record.type UserId = string & { __brand: "UserId" }) to stop mixing IDs.<T extends ...>) so errors surface at the call site, not deep inside.infer in conditional types to extract; avoid gratuitous deep conditional types (slow + unreadable).| Situation | Use |
|---|---|
| Object shape, may be extended/implemented | interface |
| Unions, intersections, mapped/conditional, tuples | type |
| Validate a literal without losing its narrow type | satisfies |
| Untrusted external data | unknown + zod/guard |
| One of N known variants | discriminated union + exhaustive switch |
| Prevent mixing same-typed domain values | branded type |
as) to silence errors → hides real mismatches. Narrow or fix the type instead; as only when you genuinely know more than the compiler (and add a comment why).enum → prefer as const union (type Role = "admin" | "user"); enums have runtime cost and odd semantics.! everywhere → masks undefined bugs; narrow with a guard or restructure.Function, object, {} as types → far too wide. {} means "anything but null/undefined".undefined confusion → a?: T and a: T | undefined differ under exactOptionalPropertyTypes.any in catch → it's unknown since TS 4.4; narrow if (e instanceof Error).Discriminated union + exhaustive never check
type Result<T> =
| { status: "ok"; data: T }
| { status: "error"; error: string };
function unwrap<T>(r: Result<T>): T {
switch (r.status) {
case "ok": return r.data;
case "error": throw new Error(r.error);
default: {
const _: never = r; // compile error if a new variant is added
return _;
}
}
}
satisfies keeps precise inference while validating shape
const routes = {
home: "/",
user: (id: string) => `/users/${id}`,
} satisfies Record<string, string | ((...a: any[]) => string)>;
routes.home; // type is "/" (not widened to string)
routes.user("42"); // typed callable
Type predicate + branded id
type UserId = string & { readonly __brand: unique symbol };
const asUserId = (s: string): UserId => s as UserId; // single controlled cast
function isNonEmpty<T>(a: T[]): a is [T, ...T[]] { return a.length > 0; }
react-expert — typing props, hooks, events, and generics in components.nodejs-backend-expert — typing handlers, config, and validated input.api-design-expert — sharing contract types across client/server.refactoring-expert — tightening types as a safe, incremental refactor.Creates, edits, and optimizes skills for Claude Code, including drafting, evaluating with test prompts, iterating on performance, and improving skill descriptions for better triggering accuracy.
npx claudepluginhub miaoge-ge/coding-agent-skills --plugin typescript-expert