用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill typescript-expert命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Bun runtime: HTTP server, file I/O, SQLite, test runner, package manager, bundler — all-in-one JS toolchain.
Clerk: Drop-in auth UI, Organizations, User management, JWT templates, webhooks, Next.js middleware integration.
Gelişmiş masaüstü, tarayıcı ve işletim sistemi kontrol yeteneği. Görsel (koordinat tabanlı) fare/klavye otomasyonu, DOM manipülasyonu, pencere yönetimi, gelişmiş dosya, ağ ve süreç yönetimini kapsar.
基于 SOC 职业分类
正在显示 SKILL.md
| name | typescript-expert |
| description | TypeScript: Type inference strategy, Generic patterns, Utility type selection, Safety patterns. |
| triggers | {"extensions":[".ts",".tsx"],"keywords":["TypeScript","type","interface","generic","infer","utility type","satisfies","as const"]} |
| auto_load_when | Writing TypeScript types or resolving type errors |
| agent | architect |
| tools | ["Read","Write","Bash"] |
Version: TS 5.6 | Focus: Type safety, inference, patterns
How much to annotate?
├── Let inference do its job:
│ └── const x = 1; → x is 1 (literal), not number
│ └── function add(a, b) → return type inferred
│
├── Explicit annotations needed when:
│ ├── Function parameters (clarify intent)
│ ├── API boundaries (incoming data)
│ ├── Complex generic returns
│ └── When inference is wrong
│
└── Avoid:
├── Over-annotating local variables
├── Type on every line
└── Using 'any' as easy way out
When to use generics:
├── Function works with multiple types
│ └── <T>(value: T): T → identity function
│
├── Type depends on another type
│ └── type Response<T> = { data: T, error?: Error }
│
├── Constraints needed:
│ └── <T extends HasId>(item: T): T['id']
│
└── When NOT to use:
└── Single specific type - just use the type
Type parameter position:
function fn<T>(...)const fn = <T>(...) => ...class Store<T> { ... }What utility to use?
├── Pick specific fields: Pick<User, 'id' | 'name'>
├── Remove specific fields: Omit<User, 'password'>
├── Make optional: Partial<User>
├── Make required: Required<Config>
├── Make readonly: Readonly<User>
├── Extract type from value: typeof user
├── Validate at runtime: z.infer<typeof Schema>
└── Function parameters: Parameters<typeof fn>
Strictness hierarchy (least to most strict):
├── any - no type checking (AVOID!)
├── unknown - something, must check before use
├── object - any non-primitive
├── string/number/etc - primitives
└── Specific literal - "exact" | "value"
Pattern: Prefer strict, relax only when needed
When to use discriminated unions:
├── API responses with different shapes
├── State machines (loading/success/error)
├── Form validation errors
└── Any "one of many" type
Pattern:
1. Common field (status, type, kind) as discriminant
2. Type is union of objects with that field
3. TypeScript can narrow in switch/if
Example:
type Result<T> =
| { status: 'success'; data: T }
| { status: 'error'; error: Error }
| { status: 'loading' }
Type-safe error handling:
├── Specific error types
│ └── type AppError = { code: string; message: string }
│
├── Result type pattern
│ └── type Result<T> = { ok: true; value: T } | { ok: false; error: E }
│
└── Never use:
└── throw in async code (harder to type)
|| Return Result instead
When to use Zod:
├── Runtime validation needed (API input, forms)
├── Want to derive TypeScript types from schema
└── Need complex validation logic
Pattern:
├── Define schema with Zod
├── Extract type: type User = z.infer<typeof UserSchema>
├── Validate at runtime: schema.parse(data) or safeParse
├── Use inferred type in code
└── Single source of truth for validation AND types
How to type modules:
├── Export interfaces/types (preferred)
│ └── export type { User, Config }
│ └── export interface { ... }
│
├── Be explicit about exports
│ └── Use package.json exports field
│ └── Define types for both import and require
│
└── Avoid:
|| Exporting 'any' types
|| Confusing default and named exports
❌ Using `any` — opts out of type checking entirely
✅ `unknown` for truly unknown types; narrow with type guards
❌ Type assertions (as Type) hiding real type errors
✅ Fix the underlying type; use `satisfies` operator for validation
❌ Overusing generics making code unreadable
✅ Generics only when the type truly varies by caller
❌ Not enabling strict mode
✅ "strict": true in tsconfig.json — catches null/undefined errors
❌ Duplicating type definitions across layers
✅ Generate types from schema (Prisma → types, OpenAPI → types)
| Feature | Syntax | When to use |
|---|---|---|
| Discriminated union | type A = { kind: 'a' } | Type-safe conditionals |
| Type guard | is narrowed type | Custom narrowing |
| Conditional type | T extends U ? A : B | Generic branching |
| Template literal | `${Status}Event` | String unions |
| Mapped type | { [K in keyof T]: ... } | Transform types |
| Infer | infer R in conditional | Extract inner type |
| Satisfies | value satisfies Type | Validate without widen |