mk-typescript
Use when writing TypeScript code, fixing type errors, or configuring strict type safety. Auto-activates on .ts/.tsx files. Covers null handling, utility types, and ESLint.
- License 许可
- MIT
- 最近更新
- 2026-11-11
- Stars
- ★ 16
- Forks
- 3
01 前言 Front Matter
- name
- mk-typescript
- description
- Use when writing TypeScript code, fixing type errors, or configuring strict type safety. Auto-activates on .ts/.tsx files. Covers null handling, utility types, and ESLint.
02 资源文件 2
- 参考文档references/review-checklist.md3.4 KB
- 参考文档references/strict-patterns.md3.1 KB
03 SKILL.md 正文
<!-- Improvements over source skills:
- Split from 361-line monolith to SKILL.md + references/ (Phase 1: CLASS A)
- Framework-agnostic (removed React-specific patterns from frontend-development)
- Integrated with security-rules.md (no
anytypes already enforced) - Added workflow phase anchoring (Phase 3 Build) -->
TypeScript Expert
Strict TypeScript patterns for type safety, null handling, and modern best practices.
When to Use
Auto-activate on: .ts, .tsx, .js, .jsx files, type errors, ESLint issues, "fix types", "add types", "TypeScript help"
Explicit: the typescript skill [concern]
Do NOT invoke for: Vue-specific patterns (use mk:vue), visual design (use mk:frontend-design)
Workflow Integration
Operates in Phase 3 (Build GREEN). Output supports the developer agent.
Process
- Detect concern — type error? new code? refactor? ESLint config?
- Load relevant reference — strict-null, type-safety, utility-types, or eslint
- Apply patterns — implement using strict TS patterns from references
- Verify —
npx tsc --noEmitmust pass with zero errors
Core Rules (always apply)
- NEVER use
any— useunknown+ type guards (security-rules.md) - NEVER use
type assertion— useunknown+ type guards (security-rules.md) - NEVER use implicit truthiness for null checks — use explicit
=== null || === undefined - ALWAYS use strict TypeScript config:
strict: true,noUncheckedIndexedAccess: true - ALWAYS use
typeimports:import type { X } from 'y' - PREFER named exports over default exports
- PREFER discriminated unions over type assertions
Anti-Patterns
| Don't | Do Instead |
|---|---|
as any or as unknown as X |
Proper type narrowing with guards |
if (value) for null check |
if (value !== null && value !== undefined) |
export default |
export const X / export function X |
Object type |
Record<string, unknown> |
| Implicit return types | Explicit return type annotations |
enum (runtime overhead) |
as const satisfies or union types |
Output Format
## TypeScript: {concern}
**Files:** {list of .ts/.tsx files modified}
**Config:** {tsconfig changes if any}
### Changes Applied
{numbered list of type improvements}
### Verification
{tsc --noEmit output — must show 0 errors}
References
| Reference | When to load | Content |
|---|---|---|
| strict-patterns.md | Type safety work | Null handling, discriminated unions, type guards, utility types |
| review-checklist.md | When reviewing TypeScript code | Prioritized checklist: CRITICAL (security), HIGH (type safety, async, errors), MEDIUM (React, perf) |
Failure Handling
| Failure | Recovery |
|---|---|
tsc --noEmit fails after changes |
Fix errors before proceeding — never ship with type errors |
| No tsconfig.json found | Suggest creating one with strict config |
| Third-party types missing | npm install @types/{package} |
Gotchas
ascast silences narrowing errors and hides real bugs —value as Usertells TS to trust you, not validate; a malformed API response passes the cast and crashes at runtime; use a type guard or Zod parse at the boundary instead.moduleResolution: "bundler"breaksimport typein non-bundler contexts — tsconfigmoduleResolution: bundler(Vite/esbuild default) allows extensionless imports that Node.js--esmrejects at runtime; flip tonodenextfor backend code or keep dual configs per target.noUncheckedIndexedAccess: truemakes every array indexT | undefined— enabling this flag (required by strict config) meansarr[0]isstring | undefinednotstring; code that was type-correct before will error until every indexed access is null-guarded.- Declaration merging in ambient
.d.tsfiles silently adds properties to global types — adeclare module 'express'block in any.d.tsin the project augments Express's types globally; two libraries doing this with conflicting shapes cause TS2300 duplicate identifier errors that appear far from the source. - Template literal types create unique brands that break assignability —
type UserId = \user_${string}`is not assignable fromstring; passing a plainstringwhereUserId` is expected fails even though values look identical at runtime; always brand at the input boundary with a parse function. enumgenerates runtime JS objects, causing tree-shaking failures — enums are not erased; aconst enuminside a library published as.jsis inlined at compile time but not consumable by projects that don't re-compile the source; useas constsatisfies patterns for exported enums.
04 同仓库更多 Skills
mk-sequential-thinking
Structured step-by-step reasoning before acting, to avoid guessing. For complex debugging, multi-step analysis, hypothesis checks. NOT for being stuck on approach (mk:problem-solving).
mk:fixture-valid
A valid fixture used to verify the skill structure validator.
invalid
暂无简介
mk:sample-skill
Sample skill for fixture purposes — small enough to land below noise floor.
mk-worktree
Manages git worktrees for parallel agent isolation: creates parallel/{name}-{timestamp} branches, merges with conflict detection. NOT for user feature branches (use git worktree directly).
mk-workflow-orchestrator
Auto-invoked 7-phase workflow for complex-feature intent; fasttrack mode for pre-approved specs. NOT for explicit single tasks (mk:cook), green-field builds (mk:autobuild), or simple fixes (mk:fix).