@neyugn/agent-kits 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +514 -0
- package/README.vi.md +410 -0
- package/README.zh.md +410 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +422 -0
- package/kits/coder/ARCHITECTURE.md +289 -0
- package/kits/coder/agents/ai-engineer.md +344 -0
- package/kits/coder/agents/backend-specialist.md +270 -0
- package/kits/coder/agents/cloud-architect.md +363 -0
- package/kits/coder/agents/code-reviewer.md +284 -0
- package/kits/coder/agents/data-engineer.md +401 -0
- package/kits/coder/agents/database-specialist.md +251 -0
- package/kits/coder/agents/debugger.md +209 -0
- package/kits/coder/agents/devops-engineer.md +281 -0
- package/kits/coder/agents/documentation-writer.md +296 -0
- package/kits/coder/agents/frontend-specialist.md +298 -0
- package/kits/coder/agents/i18n-specialist.md +348 -0
- package/kits/coder/agents/integration-specialist.md +314 -0
- package/kits/coder/agents/mobile-developer.md +271 -0
- package/kits/coder/agents/multi-tenant-architect.md +281 -0
- package/kits/coder/agents/orchestrator.md +263 -0
- package/kits/coder/agents/performance-analyst.md +327 -0
- package/kits/coder/agents/project-planner.md +277 -0
- package/kits/coder/agents/queue-specialist.md +282 -0
- package/kits/coder/agents/realtime-specialist.md +267 -0
- package/kits/coder/agents/security-auditor.md +253 -0
- package/kits/coder/agents/test-engineer.md +315 -0
- package/kits/coder/agents/ux-researcher.md +388 -0
- package/kits/coder/rules/.cursorrules +287 -0
- package/kits/coder/rules/CLAUDE.md +287 -0
- package/kits/coder/rules/CODEX.md +287 -0
- package/kits/coder/rules/GEMINI.md +287 -0
- package/kits/coder/scripts/checklist.py +318 -0
- package/kits/coder/scripts/kit_status.py +292 -0
- package/kits/coder/scripts/skills_manager.py +243 -0
- package/kits/coder/scripts/verify_all.py +391 -0
- package/kits/coder/skills/accessibility-patterns/SKILL.md +372 -0
- package/kits/coder/skills/accessibility-patterns/scripts/a11y_checker.py +211 -0
- package/kits/coder/skills/ai-rag-patterns/SKILL.md +444 -0
- package/kits/coder/skills/api-patterns/SKILL.md +316 -0
- package/kits/coder/skills/api-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/api-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/api-patterns/scripts/api_validator.py +253 -0
- package/kits/coder/skills/api-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/auth-patterns/SKILL.md +267 -0
- package/kits/coder/skills/aws-patterns/SKILL.md +576 -0
- package/kits/coder/skills/brainstorming/SKILL.md +370 -0
- package/kits/coder/skills/brainstorming/assets/.gitkeep +1 -0
- package/kits/coder/skills/brainstorming/references/deep-dive.md +21 -0
- package/kits/coder/skills/brainstorming/scripts/validate.py +56 -0
- package/kits/coder/skills/clean-code/SKILL.md +240 -0
- package/kits/coder/skills/clean-code/assets/.gitkeep +1 -0
- package/kits/coder/skills/clean-code/references/deep-dive.md +21 -0
- package/kits/coder/skills/clean-code/scripts/lint_runner.py +186 -0
- package/kits/coder/skills/clean-code/scripts/validate.py +56 -0
- package/kits/coder/skills/database-design/SKILL.md +255 -0
- package/kits/coder/skills/database-design/assets/.gitkeep +1 -0
- package/kits/coder/skills/database-design/references/deep-dive.md +21 -0
- package/kits/coder/skills/database-design/scripts/schema_validator.py +272 -0
- package/kits/coder/skills/database-design/scripts/validate.py +56 -0
- package/kits/coder/skills/docker-patterns/SKILL.md +240 -0
- package/kits/coder/skills/documentation-templates/SKILL.md +441 -0
- package/kits/coder/skills/e2e-testing/SKILL.md +457 -0
- package/kits/coder/skills/flutter-patterns/SKILL.md +330 -0
- package/kits/coder/skills/frontend-design/SKILL.md +127 -0
- package/kits/coder/skills/github-actions/SKILL.md +349 -0
- package/kits/coder/skills/gitlab-ci-patterns/SKILL.md +466 -0
- package/kits/coder/skills/graphql-patterns/SKILL.md +558 -0
- package/kits/coder/skills/i18n-localization/SKILL.md +345 -0
- package/kits/coder/skills/i18n-localization/scripts/i18n_checker.py +267 -0
- package/kits/coder/skills/kubernetes-patterns/SKILL.md +357 -0
- package/kits/coder/skills/mermaid-diagrams/SKILL.md +351 -0
- package/kits/coder/skills/mobile-design/SKILL.md +305 -0
- package/kits/coder/skills/monitoring-observability/SKILL.md +458 -0
- package/kits/coder/skills/multi-tenancy/SKILL.md +317 -0
- package/kits/coder/skills/multi-tenancy/assets/.gitkeep +1 -0
- package/kits/coder/skills/multi-tenancy/references/deep-dive.md +21 -0
- package/kits/coder/skills/multi-tenancy/scripts/validate.py +56 -0
- package/kits/coder/skills/nodejs-best-practices/SKILL.md +220 -0
- package/kits/coder/skills/performance-profiling/SKILL.md +333 -0
- package/kits/coder/skills/performance-profiling/assets/.gitkeep +1 -0
- package/kits/coder/skills/performance-profiling/references/deep-dive.md +21 -0
- package/kits/coder/skills/performance-profiling/scripts/validate.py +56 -0
- package/kits/coder/skills/plan-writing/SKILL.md +360 -0
- package/kits/coder/skills/plan-writing/assets/.gitkeep +1 -0
- package/kits/coder/skills/plan-writing/references/deep-dive.md +21 -0
- package/kits/coder/skills/plan-writing/scripts/validate.py +56 -0
- package/kits/coder/skills/postgres-patterns/SKILL.md +361 -0
- package/kits/coder/skills/prompt-engineering/SKILL.md +277 -0
- package/kits/coder/skills/queue-patterns/SKILL.md +359 -0
- package/kits/coder/skills/queue-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/queue-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/queue-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/react-native-patterns/SKILL.md +393 -0
- package/kits/coder/skills/react-patterns/SKILL.md +319 -0
- package/kits/coder/skills/realtime-patterns/SKILL.md +506 -0
- package/kits/coder/skills/realtime-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/realtime-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/realtime-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/redis-patterns/SKILL.md +484 -0
- package/kits/coder/skills/security-fundamentals/SKILL.md +363 -0
- package/kits/coder/skills/security-fundamentals/assets/.gitkeep +1 -0
- package/kits/coder/skills/security-fundamentals/references/deep-dive.md +21 -0
- package/kits/coder/skills/security-fundamentals/scripts/security_scan.py +326 -0
- package/kits/coder/skills/security-fundamentals/scripts/validate.py +56 -0
- package/kits/coder/skills/seo-patterns/SKILL.md +262 -0
- package/kits/coder/skills/seo-patterns/scripts/seo_checker.py +211 -0
- package/kits/coder/skills/systematic-debugging/SKILL.md +478 -0
- package/kits/coder/skills/systematic-debugging/assets/.gitkeep +1 -0
- package/kits/coder/skills/systematic-debugging/references/deep-dive.md +21 -0
- package/kits/coder/skills/systematic-debugging/scripts/validate.py +56 -0
- package/kits/coder/skills/tailwind-patterns/SKILL.md +395 -0
- package/kits/coder/skills/terraform-patterns/SKILL.md +470 -0
- package/kits/coder/skills/testing-patterns/SKILL.md +285 -0
- package/kits/coder/skills/testing-patterns/assets/.gitkeep +1 -0
- package/kits/coder/skills/testing-patterns/references/deep-dive.md +21 -0
- package/kits/coder/skills/testing-patterns/scripts/test_runner.py +219 -0
- package/kits/coder/skills/testing-patterns/scripts/validate.py +56 -0
- package/kits/coder/skills/typescript-patterns/SKILL.md +417 -0
- package/kits/coder/skills/ui-ux-pro-max/SKILL.md +364 -0
- package/kits/coder/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/kits/coder/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/kits/coder/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/kits/coder/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/kits/coder/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/kits/coder/skills/ui-ux-pro-max/data/prompts.csv +24 -0
- package/kits/coder/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/kits/coder/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/kits/coder/skills/ui-ux-pro-max/data/styles.csv +59 -0
- package/kits/coder/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/kits/coder/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/kits/coder/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/kits/coder/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-314.pyc +0 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-314.pyc +0 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/core.py +257 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/design_system.py +488 -0
- package/kits/coder/skills/ui-ux-pro-max/scripts/search.py +76 -0
- package/kits/coder/workflows/.gitkeep +20 -0
- package/kits/coder/workflows/create.md +152 -0
- package/kits/coder/workflows/debug.md +223 -0
- package/kits/coder/workflows/deploy.md +283 -0
- package/kits/coder/workflows/orchestrate.md +243 -0
- package/kits/coder/workflows/plan.md +134 -0
- package/kits/coder/workflows/test.md +237 -0
- package/kits/coder/workflows/ui-ux-pro-max.md +109 -0
- package/package.json +49 -0
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typescript-patterns
|
|
3
|
+
description: TypeScript advanced patterns and type-level programming. Use when writing complex types, designing APIs, optimizing type checking performance, migrating from JavaScript, or debugging type errors. Covers branded types, conditional types, generics, monorepo configuration, and modern tooling decisions.
|
|
4
|
+
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# TypeScript Patterns
|
|
8
|
+
|
|
9
|
+
> **Philosophy:** Types are documentation that never lies. Strong types catch bugs at compile time, not runtime.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## 📑 Content Map
|
|
14
|
+
|
|
15
|
+
| File | When to Read |
|
|
16
|
+
| ------------------------------- | ----------------------- |
|
|
17
|
+
| `references/advanced-types.md` | Complex type gymnastics |
|
|
18
|
+
| `references/error-patterns.md` | Debugging type errors |
|
|
19
|
+
| `references/migration-guide.md` | JS to TS migration |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## 1. Type-Level Programming Patterns
|
|
24
|
+
|
|
25
|
+
### Branded Types (Nominal Typing)
|
|
26
|
+
|
|
27
|
+
```typescript
|
|
28
|
+
type Brand<K, T> = K & { __brand: T };
|
|
29
|
+
|
|
30
|
+
type UserId = Brand<string, "UserId">;
|
|
31
|
+
type OrderId = Brand<string, "OrderId">;
|
|
32
|
+
|
|
33
|
+
// ✅ Prevents accidental mixing
|
|
34
|
+
function processOrder(orderId: OrderId, userId: UserId) {}
|
|
35
|
+
|
|
36
|
+
// Usage
|
|
37
|
+
const userId = "user-123" as UserId;
|
|
38
|
+
const orderId = "order-456" as OrderId;
|
|
39
|
+
processOrder(orderId, userId); // ✅ OK
|
|
40
|
+
processOrder(userId, orderId); // ❌ Compile error
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Use for:** Domain primitives, API boundaries, currency/units, IDs
|
|
44
|
+
|
|
45
|
+
### Conditional Types
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
// Extract promise result type
|
|
49
|
+
type Awaited<T> = T extends Promise<infer U> ? Awaited<U> : T;
|
|
50
|
+
|
|
51
|
+
// Deep readonly (recursive)
|
|
52
|
+
type DeepReadonly<T> = T extends (...args: any[]) => any
|
|
53
|
+
? T
|
|
54
|
+
: T extends object
|
|
55
|
+
? { readonly [K in keyof T]: DeepReadonly<T[K]> }
|
|
56
|
+
: T;
|
|
57
|
+
|
|
58
|
+
// Pick by value type
|
|
59
|
+
type PickByType<T, Value> = {
|
|
60
|
+
[K in keyof T as T[K] extends Value ? K : never]: T[K];
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
**Watch for:** Type instantiation depth > 10 levels
|
|
65
|
+
|
|
66
|
+
### Template Literal Types
|
|
67
|
+
|
|
68
|
+
```typescript
|
|
69
|
+
type EventName<T extends string> = `on${Capitalize<T>}`;
|
|
70
|
+
// EventName<'click'> = 'onClick'
|
|
71
|
+
|
|
72
|
+
type PropEventSource<Type> = {
|
|
73
|
+
on<Key extends string & keyof Type>(
|
|
74
|
+
eventName: `${Key}Changed`,
|
|
75
|
+
callback: (newValue: Type[Key]) => void,
|
|
76
|
+
): void;
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
|
|
82
|
+
## 2. Type Inference Techniques
|
|
83
|
+
|
|
84
|
+
### `satisfies` Operator (TS 5.0+)
|
|
85
|
+
|
|
86
|
+
```typescript
|
|
87
|
+
// ✅ Constrains while preserving literal types
|
|
88
|
+
const config = {
|
|
89
|
+
api: "https://api.example.com",
|
|
90
|
+
timeout: 5000,
|
|
91
|
+
debug: true,
|
|
92
|
+
} satisfies Record<string, string | number | boolean>;
|
|
93
|
+
|
|
94
|
+
// config.api is narrowed to string "https://api.example.com"
|
|
95
|
+
// config.timeout is narrowed to 5000, not just number
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Const Assertions
|
|
99
|
+
|
|
100
|
+
```typescript
|
|
101
|
+
const routes = ["/home", "/about", "/contact"] as const;
|
|
102
|
+
type Route = (typeof routes)[number];
|
|
103
|
+
// Route = '/home' | '/about' | '/contact'
|
|
104
|
+
|
|
105
|
+
const STATUS = {
|
|
106
|
+
PENDING: "pending",
|
|
107
|
+
DONE: "done",
|
|
108
|
+
} as const;
|
|
109
|
+
type Status = (typeof STATUS)[keyof typeof STATUS];
|
|
110
|
+
// Status = 'pending' | 'done'
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### ReturnType & Parameters
|
|
114
|
+
|
|
115
|
+
```typescript
|
|
116
|
+
function getUser(id: string) {
|
|
117
|
+
return { id, name: "John", email: "john@example.com" };
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
type User = ReturnType<typeof getUser>;
|
|
121
|
+
// { id: string; name: string; email: string }
|
|
122
|
+
|
|
123
|
+
type GetUserParams = Parameters<typeof getUser>;
|
|
124
|
+
// [id: string]
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## 3. Strict Configuration (RECOMMENDED)
|
|
130
|
+
|
|
131
|
+
### Recommended tsconfig
|
|
132
|
+
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"compilerOptions": {
|
|
136
|
+
"strict": true,
|
|
137
|
+
"noUncheckedIndexedAccess": true,
|
|
138
|
+
"noImplicitOverride": true,
|
|
139
|
+
"exactOptionalPropertyTypes": true,
|
|
140
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
141
|
+
"noFallthroughCasesInSwitch": true,
|
|
142
|
+
"forceConsistentCasingInFileNames": true
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
| Flag | What It Does |
|
|
148
|
+
| ---------------------------- | -------------------------------------------- |
|
|
149
|
+
| `strict` | Enables all strict type checking |
|
|
150
|
+
| `noUncheckedIndexedAccess` | Array/object access returns `T \| undefined` |
|
|
151
|
+
| `noImplicitOverride` | Require `override` keyword |
|
|
152
|
+
| `exactOptionalPropertyTypes` | Distinguish `undefined` vs missing |
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
## 4. Performance Optimization
|
|
157
|
+
|
|
158
|
+
### Type Checking Performance
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
# Diagnose slow type checking
|
|
162
|
+
npx tsc --extendedDiagnostics --incremental false | grep -E "Check time|Files:|Lines:|Nodes:"
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
| Problem | Solution |
|
|
166
|
+
| ----------------------------- | --------------------------- |
|
|
167
|
+
| Slow type checking | Enable `skipLibCheck: true` |
|
|
168
|
+
| Rebuilding everything | Enable `incremental: true` |
|
|
169
|
+
| Large codebase | Use Project References |
|
|
170
|
+
| "Type instantiation too deep" | See fixes below |
|
|
171
|
+
|
|
172
|
+
### Fixing "Type instantiation is excessively deep"
|
|
173
|
+
|
|
174
|
+
1. Replace type intersections (`&`) with interface extends
|
|
175
|
+
2. Split large union types (>100 members)
|
|
176
|
+
3. Use type aliases to break recursion
|
|
177
|
+
4. Limit generic constraint depth
|
|
178
|
+
|
|
179
|
+
```typescript
|
|
180
|
+
// ❌ Bad: Infinite recursion
|
|
181
|
+
type InfiniteArray<T> = T | InfiniteArray<T>[];
|
|
182
|
+
|
|
183
|
+
// ✅ Good: Limited recursion depth
|
|
184
|
+
type NestedArray<T, D extends number = 5> = D extends 0
|
|
185
|
+
? T
|
|
186
|
+
: T | NestedArray<T, Prev[D]>[];
|
|
187
|
+
|
|
188
|
+
type Prev = [never, 0, 1, 2, 3, 4];
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
---
|
|
192
|
+
|
|
193
|
+
## 5. Common Error Patterns
|
|
194
|
+
|
|
195
|
+
### "The inferred type of X cannot be named"
|
|
196
|
+
|
|
197
|
+
| Cause | Fix |
|
|
198
|
+
| ------------------- | ------------------------------------ |
|
|
199
|
+
| Missing type export | Export the required type explicitly |
|
|
200
|
+
| Circular dependency | Use type-only imports: `import type` |
|
|
201
|
+
| Complex inference | Use `ReturnType<typeof fn>` |
|
|
202
|
+
|
|
203
|
+
### "Cannot find module"
|
|
204
|
+
|
|
205
|
+
| Cause | Fix |
|
|
206
|
+
| ---------------------- | ----------------------------------------- |
|
|
207
|
+
| Wrong moduleResolution | Match your bundler (node, bundler) |
|
|
208
|
+
| Missing baseUrl | Check tsconfig paths alignment |
|
|
209
|
+
| Monorepo setup | Use workspace protocol (workspace:\*) |
|
|
210
|
+
| Cache issues | `rm -rf node_modules/.cache .tsbuildinfo` |
|
|
211
|
+
|
|
212
|
+
### Missing Type Declarations
|
|
213
|
+
|
|
214
|
+
```typescript
|
|
215
|
+
// types/ambient.d.ts
|
|
216
|
+
declare module "untyped-package" {
|
|
217
|
+
const value: unknown;
|
|
218
|
+
export default value;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// For CJS interop
|
|
222
|
+
declare module "cjs-package" {
|
|
223
|
+
const value: unknown;
|
|
224
|
+
export = value;
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## 6. Module System Decisions
|
|
231
|
+
|
|
232
|
+
### ESM-First Approach
|
|
233
|
+
|
|
234
|
+
| Configuration | Value |
|
|
235
|
+
| ------------------- | ------------------------- |
|
|
236
|
+
| package.json `type` | `"module"` |
|
|
237
|
+
| moduleResolution | `"bundler"` or `"node16"` |
|
|
238
|
+
| module | `"esnext"` or `"node16"` |
|
|
239
|
+
|
|
240
|
+
### CJS Interop
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
// ✅ Dynamic import for CJS in ESM
|
|
244
|
+
const pkg = await import("cjs-package");
|
|
245
|
+
const defaultExport = pkg.default || pkg;
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
---
|
|
249
|
+
|
|
250
|
+
## 7. Monorepo Configuration
|
|
251
|
+
|
|
252
|
+
### Project References
|
|
253
|
+
|
|
254
|
+
```json
|
|
255
|
+
// Root tsconfig.json
|
|
256
|
+
{
|
|
257
|
+
"references": [
|
|
258
|
+
{ "path": "./packages/core" },
|
|
259
|
+
{ "path": "./packages/ui" },
|
|
260
|
+
{ "path": "./apps/web" }
|
|
261
|
+
],
|
|
262
|
+
"compilerOptions": {
|
|
263
|
+
"composite": true,
|
|
264
|
+
"declaration": true,
|
|
265
|
+
"declarationMap": true
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Nx vs Turborepo Decision
|
|
271
|
+
|
|
272
|
+
| Choose | When |
|
|
273
|
+
| ------------- | ------------------------------------- |
|
|
274
|
+
| **Turborepo** | Simple structure, speed, <20 packages |
|
|
275
|
+
| **Nx** | Complex deps, visualization, plugins |
|
|
276
|
+
|
|
277
|
+
---
|
|
278
|
+
|
|
279
|
+
## 8. Tooling Decisions
|
|
280
|
+
|
|
281
|
+
### Biome vs ESLint
|
|
282
|
+
|
|
283
|
+
| Choose | When |
|
|
284
|
+
| ---------- | ---------------------------------------- |
|
|
285
|
+
| **Biome** | Speed critical, single tool, TS-first |
|
|
286
|
+
| **ESLint** | Need specific rules, Vue/Angular support |
|
|
287
|
+
|
|
288
|
+
### Type Testing
|
|
289
|
+
|
|
290
|
+
```typescript
|
|
291
|
+
// avatar.test-d.ts (Vitest type testing)
|
|
292
|
+
import { expectTypeOf } from "vitest";
|
|
293
|
+
import type { Avatar } from "./avatar";
|
|
294
|
+
|
|
295
|
+
test("Avatar props are correctly typed", () => {
|
|
296
|
+
expectTypeOf<Avatar>().toHaveProperty("size");
|
|
297
|
+
expectTypeOf<Avatar["size"]>().toEqualTypeOf<"sm" | "md" | "lg">();
|
|
298
|
+
});
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
**When to test types:** Library APIs, generic functions, type utilities
|
|
302
|
+
|
|
303
|
+
---
|
|
304
|
+
|
|
305
|
+
## 9. Best Practices
|
|
306
|
+
|
|
307
|
+
### Prefer Interface over Type (for objects)
|
|
308
|
+
|
|
309
|
+
```typescript
|
|
310
|
+
// ✅ Better error messages, extends support
|
|
311
|
+
interface User {
|
|
312
|
+
id: string;
|
|
313
|
+
name: string;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// ✅ Use type for unions, primitives, functions
|
|
317
|
+
type Status = "active" | "inactive";
|
|
318
|
+
type Handler = (event: Event) => void;
|
|
319
|
+
```
|
|
320
|
+
|
|
321
|
+
### Use Type Guards
|
|
322
|
+
|
|
323
|
+
```typescript
|
|
324
|
+
function isUser(value: unknown): value is User {
|
|
325
|
+
return (
|
|
326
|
+
typeof value === "object" &&
|
|
327
|
+
value !== null &&
|
|
328
|
+
"id" in value &&
|
|
329
|
+
"name" in value
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Discriminated unions for error handling
|
|
334
|
+
type Result<T> = { success: true; data: T } | { success: false; error: string };
|
|
335
|
+
```
|
|
336
|
+
|
|
337
|
+
### Exhaustive Switch
|
|
338
|
+
|
|
339
|
+
```typescript
|
|
340
|
+
function assertNever(x: never): never {
|
|
341
|
+
throw new Error(`Unexpected value: ${x}`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function handleStatus(status: Status) {
|
|
345
|
+
switch (status) {
|
|
346
|
+
case "active":
|
|
347
|
+
return "Active";
|
|
348
|
+
case "inactive":
|
|
349
|
+
return "Inactive";
|
|
350
|
+
default:
|
|
351
|
+
return assertNever(status); // Catches missing cases
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
---
|
|
357
|
+
|
|
358
|
+
## 10. Anti-Patterns
|
|
359
|
+
|
|
360
|
+
| ❌ Don't | ✅ Do |
|
|
361
|
+
| --------------------------------- | -------------------------------- |
|
|
362
|
+
| `any` everywhere | `unknown` with type guards |
|
|
363
|
+
| Excessive type assertions (`as`) | Proper type inference |
|
|
364
|
+
| Ignoring strict mode | Enable all strict flags |
|
|
365
|
+
| Complex mapped types in hot paths | Pre-compute, cache types |
|
|
366
|
+
| Index as object key without check | `noUncheckedIndexedAccess: true` |
|
|
367
|
+
| Type in separate file from impl | Co-locate types with code |
|
|
368
|
+
| Over-complicated generics | Simpler solution first |
|
|
369
|
+
|
|
370
|
+
---
|
|
371
|
+
|
|
372
|
+
## 11. Migration Strategies
|
|
373
|
+
|
|
374
|
+
### JavaScript to TypeScript
|
|
375
|
+
|
|
376
|
+
| Phase | Action |
|
|
377
|
+
| ----- | --------------------------------------- |
|
|
378
|
+
| 1 | Enable `allowJs`, `checkJs` in tsconfig |
|
|
379
|
+
| 2 | Rename files `.js` → `.ts` gradually |
|
|
380
|
+
| 3 | Add types file by file |
|
|
381
|
+
| 4 | Enable strict mode progressively |
|
|
382
|
+
|
|
383
|
+
### Useful Tools
|
|
384
|
+
|
|
385
|
+
| Tool | Purpose |
|
|
386
|
+
| ------------ | ------------------------------- |
|
|
387
|
+
| `ts-migrate` | Automated migration from Airbnb |
|
|
388
|
+
| `typesync` | Install missing @types |
|
|
389
|
+
| `TypeStat` | Auto-fix TypeScript types |
|
|
390
|
+
|
|
391
|
+
---
|
|
392
|
+
|
|
393
|
+
## 12. Code Review Checklist
|
|
394
|
+
|
|
395
|
+
- [ ] No implicit `any` types
|
|
396
|
+
- [ ] Return types explicit for public APIs
|
|
397
|
+
- [ ] Generic constraints properly defined
|
|
398
|
+
- [ ] Discriminated unions for errors
|
|
399
|
+
- [ ] Type guards where needed
|
|
400
|
+
- [ ] No circular dependencies
|
|
401
|
+
- [ ] Consistent import style (absolute/relative)
|
|
402
|
+
- [ ] No excessive type assertions
|
|
403
|
+
|
|
404
|
+
---
|
|
405
|
+
|
|
406
|
+
## Related Skills
|
|
407
|
+
|
|
408
|
+
| Need | Skill |
|
|
409
|
+
| ------------------ | ----------------------- |
|
|
410
|
+
| React + TypeScript | `react-patterns` |
|
|
411
|
+
| API design | `api-patterns` |
|
|
412
|
+
| Testing | `testing-patterns` |
|
|
413
|
+
| Performance | `performance-profiling` |
|
|
414
|
+
|
|
415
|
+
---
|
|
416
|
+
|
|
417
|
+
> **Remember:** Good TypeScript code reads like documentation. If the types are confusing, the code is probably confusing too.
|