Install
$ agentstack add skill-miaoge-ge-coding-agent-skills-typescript-expert ✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
Verified badge
Passed review? Show it. Paste this badge into your README, it links to the public security report.
Reliability & compatibility
Declared compatibility
Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.
We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.
How agent discovery & health will work →About
TypeScript Expert
> 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.
When to Use
- Writing or refactoring TypeScript and wanting types that catch real bugs.
- A cryptic type error needs explaining or fixing (
not assignable,excessively deep, variance complaints). - Designing generic, reusable library types or public API surfaces.
- Configuring
tsconfig.json, writing.d.ts, or migrating JS → TS.
When NOT to Use
- Runtime/algorithm logic unrelated to typing → relevant language skill.
- React-specific component/hook patterns →
react-expert. - Backend framework wiring →
nodejs-backend-expert.
Core Principles
1. Strictness is non-negotiable
strict: trueis the floor. AddnoUncheckedIndexedAccess(array access isT | undefined), and for librariesexactOptionalPropertyTypes+noImplicitOverride.- Don't disable
strictto "make it compile" — the error is usually a real bug. Fix the model.
2. any vs unknown
anydisables checking and silently spreads. Ban it (@typescript-eslint/no-explicit-any).- At untyped boundaries (JSON,
catch, 3rd-party) useunknown, then narrow with a guard or schema (zod) before use.
3. Let inference work; annotate intent
- Annotate function parameters and public return types; let locals infer.
- Use
as constfor literal tuples/objects, andsatisfiesto validate a value against a type without widening it (keeps the precise inferred type).
4. Model with the type system
- Discriminated unions for state/variants; a shared literal
kind/statusfield unlocks exhaustive narrowing. - Derive, don't duplicate:
ReturnType,Parameters,Awaited,keyof, indexed access (T["field"]),Pick/Omit/Record. - Newtype/branded types for domain values (
type UserId = string & { __brand: "UserId" }) to stop mixing IDs.
5. Generics with constraints
- Add a type parameter only when callers vary the type. Constrain it (``) so errors surface at the call site, not deep inside.
- Use
inferin conditional types to extract; avoid gratuitous deep conditional types (slow + unreadable).
Decision Guide
| 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 |
Common Mistakes
- Type assertions (
as) to silence errors → hides real mismatches. Narrow or fix the type instead;asonly when you genuinely know more than the compiler (and add a comment why). enum→ preferas constunion (type Role = "admin" | "user"); enums have runtime cost and odd semantics.- Non-null
!everywhere → masksundefinedbugs; narrow with a guard or restructure. Function,object,{}as types → far too wide.{}means "anything but null/undefined".- Optional vs
undefinedconfusion →a?: Tanda: T | undefineddiffer underexactOptionalPropertyTypes. anyin catch → it'sunknownsince TS 4.4; narrowif (e instanceof Error).
Examples
Discriminated union + exhaustive never check
type Result =
| { status: "ok"; data: T }
| { status: "error"; error: string };
function unwrap(r: Result): 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)>;
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(a: T[]): a is [T, ...T[]] { return a.length > 0; }
See Also
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.
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: Miaoge-Ge
- Source: Miaoge-Ge/coding-agent-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet, be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.