typescript-pro
TypeScript expert for advanced type systems, large-scale applications, and type-safe development. Trigger: When writing TypeScript code - types, interfaces, generics, advanced patterns.
- License 许可
- Apache-2.0
- 最近更新
- 2026-08-26
- Stars
- ★ 1
- Forks
- 0
01 前言 Front Matter
- name
- typescript-pro
- license
- Apache-2.0
- metadata
- { "author": "gentleman-programming", "version": "1.1" }
- description
- TypeScript expert for advanced type systems, large-scale applications, and type-safe development. Trigger: When writing TypeScript code - types, interfaces, generics, advanced patterns.
02 资源文件 9
- 参考文档.skill-meta.json499 B
- 脚本assets/01-advanced-types.ts375 B
- 脚本assets/typescript-patterns-example.ts1.5 KB
- 参考文档README.md1.9 KB
- 参考文档references/01-advanced-types.md261 B
- 参考文档references/02-generics.md269 B
- 参考文档references/03-utility-types.md240 B
- 参考文档references/advanced-types.md1.1 KB
- 参考文档references/generics-type-safety.md1.2 KB
03 SKILL.md 正文
When to Use
- TypeScript development (any level)
- Advanced type systems and type-level programming
- Large-scale TypeScript applications
- Type-safe code patterns
- Writing types, interfaces, generics
- Strict mode development
Core Expertise
Foundational Patterns (REQUIRED)
Const Types Pattern (REQUIRED)
// ✅ ALWAYS: Create const object first, then extract type
const STATUS = {
ACTIVE: "active",
INACTIVE: "inactive",
PENDING: "pending",
} as const;
type Status = (typeof STATUS)[keyof typeof STATUS];
// ❌ NEVER: Direct union types
type Status = "active" | "inactive" | "pending";
Why? Single source of truth, runtime values, autocomplete, easier refactoring.
Flat Interfaces (REQUIRED)
// ✅ ALWAYS: One level depth, nested objects → dedicated interface
interface UserAddress {
street: string;
city: string;
}
interface User {
id: string;
name: string;
address: UserAddress; // Reference, not inline
}
interface Admin extends User {
permissions: string[];
}
// ❌ NEVER: Inline nested objects
interface User {
address: { street: string; city: string }; // NO!
}
Never Use any
// ✅ Use unknown for truly unknown types
function parse(input: unknown): User {
if (isUser(input)) return input;
throw new Error("Invalid input");
}
// ✅ Use generics for flexible types
function first<T>(arr: T[]): T | undefined {
return arr[0];
}
// ❌ NEVER
function parse(input: any): any { }
Utility Types Quick Reference
Pick<User, "id" | "name"> // Select fields
Omit<User, "id"> // Exclude fields
Partial<User> // All optional
Required<User> // All required
Readonly<User> // All readonly
Record<string, User> // Object type
Extract<Union, "a" | "b"> // Extract from union
Exclude<Union, "a"> // Exclude from union
NonNullable<T | null> // Remove null/undefined
ReturnType<typeof fn> // Function return type
Parameters<typeof fn> // Function params tuple
Type Guards
function isUser(value: unknown): value is User {
return (
typeof value === "object" &&
value !== null &&
"id" in value &&
"name" in value
);
}
Import Types
import type { User } from "./types";
import { createUser, type Config } from "./utils";
Advanced Type System
- Conditional types and mapped types
- Template literal types
- Recursive types and type inference
- Discriminated unions and exhaustive checking
- Generic constraints and variance
Type-Level Programming
- DeepPartial, DeepReadonly
- ReturnType inference
- Template literal types for events
- Mapped type utilities
Design Patterns
- Repository pattern with generics
- Dependency injection
- Event-driven architectures
- Factory patterns with type safety
Best Practices
- Use strict mode (enable all checks)
- Prefer interfaces over types for objects
- Use satisfies operator for inference
- Implement proper error handling
- Extract types to single source of truth
- Keep interfaces flat (no nesting)
Resources
See references/ for detailed guides:
references/advanced-types.md- Const types, flat interfaces, utility types, conditional typesreferences/generics-type-safety.md- Generic functions, interfaces, constraints, type inference
Code examples in assets/:
assets/typescript-patterns-example.ts- Complete working examples with const types, interfaces, generics, type guards, mapped types, template literal types
External Resources
04 同仓库更多 Skills
zustand-5
Zustand 5 state management patterns. Trigger: When managing React state with Zustand.
zod-4
Zod 4 schema validation patterns. Trigger: When using Zod for validation - breaking changes from v3.
x-bookmark-quote-posts
Workflow para revisar bookmarks de X/Twitter y convertirlos en drafts de quote posts. Accede a la sección de bookmarks vía browser headless, extrae posts recientes, y genera drafts con voz personal del usuario. No publica ni muta X — solo genera contenido para revisión. Trigger: X bookmarks, Twitter bookmarks, quote posts, bookmark automation, crear quote posts, revisar bookmarks, growth content X.
writing-skills
Use when creating new skills, editing existing skills, or verifying skills work before deployment
writing-plans
Use when you have a spec or requirements for a multi-step task, before touching code
work-unit-commits
Plan commits as reviewable work units. Trigger: implementation, commit splitting, chained PRs, or keeping tests and docs with code.