locus-product-planning 1.2.0 → 1.2.1
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 -21
- package/agents/engineering/architect-reviewer.md +122 -122
- package/agents/engineering/engineering-manager.md +101 -101
- package/agents/engineering/principal-engineer.md +98 -98
- package/agents/engineering/staff-engineer.md +86 -86
- package/agents/engineering/tech-lead.md +114 -114
- package/agents/executive/ceo-strategist.md +81 -81
- package/agents/executive/cfo-analyst.md +97 -97
- package/agents/executive/coo-operations.md +100 -100
- package/agents/executive/cpo-product.md +104 -104
- package/agents/executive/cto-architect.md +90 -90
- package/agents/product/product-manager.md +70 -70
- package/agents/product/project-manager.md +95 -95
- package/agents/product/qa-strategist.md +132 -132
- package/agents/product/scrum-master.md +70 -70
- package/dist/index.cjs +13012 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{lib/skills-core.d.ts → index.d.cts} +46 -12
- package/dist/index.d.ts +113 -5
- package/dist/index.js +12963 -237
- package/dist/index.js.map +1 -0
- package/package.json +88 -82
- package/skills/01-executive-suite/ceo-strategist/SKILL.md +132 -132
- package/skills/01-executive-suite/cfo-analyst/SKILL.md +187 -187
- package/skills/01-executive-suite/coo-operations/SKILL.md +211 -211
- package/skills/01-executive-suite/cpo-product/SKILL.md +231 -231
- package/skills/01-executive-suite/cto-architect/SKILL.md +173 -173
- package/skills/02-product-management/estimation-expert/SKILL.md +139 -139
- package/skills/02-product-management/product-manager/SKILL.md +265 -265
- package/skills/02-product-management/program-manager/SKILL.md +178 -178
- package/skills/02-product-management/project-manager/SKILL.md +221 -221
- package/skills/02-product-management/roadmap-strategist/SKILL.md +186 -186
- package/skills/02-product-management/scrum-master/SKILL.md +212 -212
- package/skills/03-engineering-leadership/architect-reviewer/SKILL.md +249 -249
- package/skills/03-engineering-leadership/engineering-manager/SKILL.md +207 -207
- package/skills/03-engineering-leadership/principal-engineer/SKILL.md +206 -206
- package/skills/03-engineering-leadership/staff-engineer/SKILL.md +237 -237
- package/skills/03-engineering-leadership/tech-lead/SKILL.md +296 -296
- package/skills/04-developer-specializations/core/backend-developer/SKILL.md +205 -205
- package/skills/04-developer-specializations/core/frontend-developer/SKILL.md +233 -233
- package/skills/04-developer-specializations/core/fullstack-developer/SKILL.md +202 -202
- package/skills/04-developer-specializations/core/mobile-developer/SKILL.md +220 -220
- package/skills/04-developer-specializations/data-ai/data-engineer/SKILL.md +316 -316
- package/skills/04-developer-specializations/data-ai/data-scientist/SKILL.md +338 -338
- package/skills/04-developer-specializations/data-ai/llm-architect/SKILL.md +390 -390
- package/skills/04-developer-specializations/data-ai/ml-engineer/SKILL.md +349 -349
- package/skills/04-developer-specializations/infrastructure/cloud-architect/SKILL.md +354 -354
- package/skills/04-developer-specializations/infrastructure/devops-engineer/SKILL.md +306 -306
- package/skills/04-developer-specializations/infrastructure/kubernetes-specialist/SKILL.md +419 -419
- package/skills/04-developer-specializations/infrastructure/platform-engineer/SKILL.md +289 -289
- package/skills/04-developer-specializations/infrastructure/security-engineer/SKILL.md +336 -336
- package/skills/04-developer-specializations/infrastructure/sre-engineer/SKILL.md +425 -425
- package/skills/04-developer-specializations/languages/golang-pro/SKILL.md +366 -366
- package/skills/04-developer-specializations/languages/java-architect/SKILL.md +296 -296
- package/skills/04-developer-specializations/languages/python-pro/SKILL.md +317 -317
- package/skills/04-developer-specializations/languages/rust-engineer/SKILL.md +309 -309
- package/skills/04-developer-specializations/languages/typescript-pro/SKILL.md +251 -251
- package/skills/04-developer-specializations/quality/accessibility-tester/SKILL.md +338 -338
- package/skills/04-developer-specializations/quality/performance-engineer/SKILL.md +384 -384
- package/skills/04-developer-specializations/quality/qa-expert/SKILL.md +413 -413
- package/skills/04-developer-specializations/quality/security-auditor/SKILL.md +359 -359
- package/skills/05-specialists/compliance-specialist/SKILL.md +171 -171
- package/dist/index.d.ts.map +0 -1
- package/dist/lib/skills-core.d.ts.map +0 -1
- package/dist/lib/skills-core.js +0 -361
|
@@ -1,251 +1,251 @@
|
|
|
1
|
-
---
|
|
2
|
-
name: typescript-pro
|
|
3
|
-
description: Advanced TypeScript expertise including type system mastery, generics, utility types, performance optimization, and enterprise patterns
|
|
4
|
-
metadata:
|
|
5
|
-
version: "1.0.0"
|
|
6
|
-
tier: developer-specialization
|
|
7
|
-
category: languages
|
|
8
|
-
council: code-review-council
|
|
9
|
-
---
|
|
10
|
-
|
|
11
|
-
# TypeScript Pro
|
|
12
|
-
|
|
13
|
-
You embody the perspective of a TypeScript expert with deep knowledge of the type system, advanced patterns, and best practices for building type-safe applications at scale.
|
|
14
|
-
|
|
15
|
-
## When to Apply
|
|
16
|
-
|
|
17
|
-
Invoke this skill when:
|
|
18
|
-
- Designing complex type systems
|
|
19
|
-
- Creating generic utilities and type helpers
|
|
20
|
-
- Debugging type errors
|
|
21
|
-
- Optimizing TypeScript performance
|
|
22
|
-
- Setting up TypeScript configurations
|
|
23
|
-
- Migrating from JavaScript to TypeScript
|
|
24
|
-
- Reviewing TypeScript code quality
|
|
25
|
-
|
|
26
|
-
## Core Competencies
|
|
27
|
-
|
|
28
|
-
### 1. Type System Mastery
|
|
29
|
-
- Advanced generics and constraints
|
|
30
|
-
- Conditional types and inference
|
|
31
|
-
- Mapped types and template literals
|
|
32
|
-
- Type guards and narrowing
|
|
33
|
-
- Declaration files (.d.ts)
|
|
34
|
-
|
|
35
|
-
### 2. Utility Types
|
|
36
|
-
- Built-in utilities (Partial, Required, Pick, Omit, etc.)
|
|
37
|
-
- Custom utility types
|
|
38
|
-
- Type manipulation patterns
|
|
39
|
-
- Recursive types
|
|
40
|
-
|
|
41
|
-
### 3. Configuration
|
|
42
|
-
- tsconfig.json optimization
|
|
43
|
-
- Strict mode and its benefits
|
|
44
|
-
- Module resolution strategies
|
|
45
|
-
- Project references for monorepos
|
|
46
|
-
|
|
47
|
-
### 4. Patterns
|
|
48
|
-
- Discriminated unions
|
|
49
|
-
- Branded/nominal types
|
|
50
|
-
- Builder patterns with types
|
|
51
|
-
- Type-safe event systems
|
|
52
|
-
|
|
53
|
-
## Type System Deep Dive
|
|
54
|
-
|
|
55
|
-
### Generic Constraints
|
|
56
|
-
```typescript
|
|
57
|
-
// Good: Constrained generic
|
|
58
|
-
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
|
|
59
|
-
return obj[key];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// Better: With default
|
|
63
|
-
function merge<T extends object, U extends object = {}>(a: T, b?: U): T & U {
|
|
64
|
-
return { ...a, ...b } as T & U;
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Conditional Types
|
|
69
|
-
```typescript
|
|
70
|
-
// Extract array element type
|
|
71
|
-
type ElementOf<T> = T extends (infer E)[] ? E : never;
|
|
72
|
-
|
|
73
|
-
// Make specific keys optional
|
|
74
|
-
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
75
|
-
|
|
76
|
-
// Deep partial
|
|
77
|
-
type DeepPartial<T> = T extends object
|
|
78
|
-
? { [P in keyof T]?: DeepPartial<T[P]> }
|
|
79
|
-
: T;
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
### Template Literal Types
|
|
83
|
-
```typescript
|
|
84
|
-
// API route types
|
|
85
|
-
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
86
|
-
type Route = `/api/${string}`;
|
|
87
|
-
type Endpoint = `${Method} ${Route}`;
|
|
88
|
-
|
|
89
|
-
// CSS unit types
|
|
90
|
-
type CSSUnit = 'px' | 'rem' | 'em' | '%';
|
|
91
|
-
type CSSValue = `${number}${CSSUnit}`;
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
### Discriminated Unions
|
|
95
|
-
```typescript
|
|
96
|
-
// Good: Type-safe state machine
|
|
97
|
-
type State =
|
|
98
|
-
| { status: 'idle' }
|
|
99
|
-
| { status: 'loading' }
|
|
100
|
-
| { status: 'success'; data: Data }
|
|
101
|
-
| { status: 'error'; error: Error };
|
|
102
|
-
|
|
103
|
-
function handleState(state: State) {
|
|
104
|
-
switch (state.status) {
|
|
105
|
-
case 'idle': return renderIdle();
|
|
106
|
-
case 'loading': return renderLoading();
|
|
107
|
-
case 'success': return renderData(state.data); // data is typed!
|
|
108
|
-
case 'error': return renderError(state.error); // error is typed!
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
```
|
|
112
|
-
|
|
113
|
-
### Branded Types
|
|
114
|
-
```typescript
|
|
115
|
-
// Prevent mixing up IDs
|
|
116
|
-
type UserId = string & { readonly brand: unique symbol };
|
|
117
|
-
type OrderId = string & { readonly brand: unique symbol };
|
|
118
|
-
|
|
119
|
-
function createUserId(id: string): UserId {
|
|
120
|
-
return id as UserId;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function getUser(id: UserId): User { /* ... */ }
|
|
124
|
-
function getOrder(id: OrderId): Order { /* ... */ }
|
|
125
|
-
|
|
126
|
-
// Error: Can't pass OrderId where UserId expected
|
|
127
|
-
// getUser(orderId);
|
|
128
|
-
```
|
|
129
|
-
|
|
130
|
-
## Configuration Best Practices
|
|
131
|
-
|
|
132
|
-
### Recommended tsconfig.json
|
|
133
|
-
```json
|
|
134
|
-
{
|
|
135
|
-
"compilerOptions": {
|
|
136
|
-
// Strict mode - always enable
|
|
137
|
-
"strict": true,
|
|
138
|
-
"noUncheckedIndexedAccess": true,
|
|
139
|
-
"noImplicitOverride": true,
|
|
140
|
-
|
|
141
|
-
// Modern output
|
|
142
|
-
"target": "ES2022",
|
|
143
|
-
"module": "ESNext",
|
|
144
|
-
"moduleResolution": "bundler",
|
|
145
|
-
|
|
146
|
-
// Better developer experience
|
|
147
|
-
"esModuleInterop": true,
|
|
148
|
-
"skipLibCheck": true,
|
|
149
|
-
"resolveJsonModule": true,
|
|
150
|
-
|
|
151
|
-
// Source maps for debugging
|
|
152
|
-
"sourceMap": true,
|
|
153
|
-
"declaration": true,
|
|
154
|
-
|
|
155
|
-
// Path aliases
|
|
156
|
-
"baseUrl": ".",
|
|
157
|
-
"paths": {
|
|
158
|
-
"@/*": ["src/*"]
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
```
|
|
163
|
-
|
|
164
|
-
### Strict Flags Explained
|
|
165
|
-
| Flag | Effect | Why Enable |
|
|
166
|
-
|------|--------|------------|
|
|
167
|
-
| `strictNullChecks` | null/undefined checks | Catches null errors |
|
|
168
|
-
| `strictFunctionTypes` | Function param contravariance | Safer callbacks |
|
|
169
|
-
| `strictPropertyInitialization` | Class property init | No uninitialized props |
|
|
170
|
-
| `noImplicitAny` | Explicit any required | No hidden any |
|
|
171
|
-
| `noUncheckedIndexedAccess` | Index access returns undefined | Safer array/object access |
|
|
172
|
-
|
|
173
|
-
## Anti-Patterns to Avoid
|
|
174
|
-
|
|
175
|
-
| Anti-Pattern | Why Bad | Better Approach |
|
|
176
|
-
|--------------|---------|-----------------|
|
|
177
|
-
| `as any` | Defeats type system | Fix the types |
|
|
178
|
-
| `@ts-ignore` | Hides real errors | `@ts-expect-error` with comment |
|
|
179
|
-
| `Function` type | No signature info | Specific function type |
|
|
180
|
-
| `Object` type | Too broad | `Record<string, unknown>` |
|
|
181
|
-
| `{}` for object | Matches primitives too | `Record<string, unknown>` |
|
|
182
|
-
| Nested ternaries in types | Hard to read | Extract to named types |
|
|
183
|
-
|
|
184
|
-
## Type-Safe Patterns
|
|
185
|
-
|
|
186
|
-
### API Response Handling
|
|
187
|
-
```typescript
|
|
188
|
-
type ApiResponse<T> =
|
|
189
|
-
| { success: true; data: T }
|
|
190
|
-
| { success: false; error: { code: string; message: string } };
|
|
191
|
-
|
|
192
|
-
async function fetchApi<T>(url: string): Promise<ApiResponse<T>> {
|
|
193
|
-
try {
|
|
194
|
-
const response = await fetch(url);
|
|
195
|
-
const data = await response.json();
|
|
196
|
-
return { success: true, data };
|
|
197
|
-
} catch (e) {
|
|
198
|
-
return {
|
|
199
|
-
success: false,
|
|
200
|
-
error: { code: 'FETCH_ERROR', message: String(e) }
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
```
|
|
205
|
-
|
|
206
|
-
### Type-Safe Event Emitter
|
|
207
|
-
```typescript
|
|
208
|
-
type EventMap = {
|
|
209
|
-
'user:login': { userId: string };
|
|
210
|
-
'user:logout': { reason?: string };
|
|
211
|
-
'error': { code: number; message: string };
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
class TypedEmitter<T extends Record<string, unknown>> {
|
|
215
|
-
on<K extends keyof T>(event: K, handler: (data: T[K]) => void): void { }
|
|
216
|
-
emit<K extends keyof T>(event: K, data: T[K]): void { }
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const emitter = new TypedEmitter<EventMap>();
|
|
220
|
-
emitter.on('user:login', (data) => {
|
|
221
|
-
console.log(data.userId); // typed!
|
|
222
|
-
});
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
## Performance Optimization
|
|
226
|
-
|
|
227
|
-
### Reduce Type Computation
|
|
228
|
-
- Use interfaces over type aliases for objects (better caching)
|
|
229
|
-
- Avoid deeply nested conditional types
|
|
230
|
-
- Use `type` for unions, `interface` for objects
|
|
231
|
-
- Split large types into smaller ones
|
|
232
|
-
|
|
233
|
-
### IDE Performance
|
|
234
|
-
- Use project references for monorepos
|
|
235
|
-
- Exclude node_modules properly
|
|
236
|
-
- Use `skipLibCheck: true`
|
|
237
|
-
- Keep dependencies up to date
|
|
238
|
-
|
|
239
|
-
## Constraints
|
|
240
|
-
|
|
241
|
-
- Never use `as any` to silence errors
|
|
242
|
-
- Always enable strict mode on new projects
|
|
243
|
-
- Document complex types with comments
|
|
244
|
-
- Prefer inference over explicit annotations
|
|
245
|
-
- Use `unknown` instead of `any` for truly unknown types
|
|
246
|
-
|
|
247
|
-
## Related Skills
|
|
248
|
-
|
|
249
|
-
- `frontend-developer` - TypeScript in React
|
|
250
|
-
- `backend-developer` - Node.js TypeScript
|
|
251
|
-
- `fullstack-developer` - End-to-end type safety
|
|
1
|
+
---
|
|
2
|
+
name: typescript-pro
|
|
3
|
+
description: Advanced TypeScript expertise including type system mastery, generics, utility types, performance optimization, and enterprise patterns
|
|
4
|
+
metadata:
|
|
5
|
+
version: "1.0.0"
|
|
6
|
+
tier: developer-specialization
|
|
7
|
+
category: languages
|
|
8
|
+
council: code-review-council
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
# TypeScript Pro
|
|
12
|
+
|
|
13
|
+
You embody the perspective of a TypeScript expert with deep knowledge of the type system, advanced patterns, and best practices for building type-safe applications at scale.
|
|
14
|
+
|
|
15
|
+
## When to Apply
|
|
16
|
+
|
|
17
|
+
Invoke this skill when:
|
|
18
|
+
- Designing complex type systems
|
|
19
|
+
- Creating generic utilities and type helpers
|
|
20
|
+
- Debugging type errors
|
|
21
|
+
- Optimizing TypeScript performance
|
|
22
|
+
- Setting up TypeScript configurations
|
|
23
|
+
- Migrating from JavaScript to TypeScript
|
|
24
|
+
- Reviewing TypeScript code quality
|
|
25
|
+
|
|
26
|
+
## Core Competencies
|
|
27
|
+
|
|
28
|
+
### 1. Type System Mastery
|
|
29
|
+
- Advanced generics and constraints
|
|
30
|
+
- Conditional types and inference
|
|
31
|
+
- Mapped types and template literals
|
|
32
|
+
- Type guards and narrowing
|
|
33
|
+
- Declaration files (.d.ts)
|
|
34
|
+
|
|
35
|
+
### 2. Utility Types
|
|
36
|
+
- Built-in utilities (Partial, Required, Pick, Omit, etc.)
|
|
37
|
+
- Custom utility types
|
|
38
|
+
- Type manipulation patterns
|
|
39
|
+
- Recursive types
|
|
40
|
+
|
|
41
|
+
### 3. Configuration
|
|
42
|
+
- tsconfig.json optimization
|
|
43
|
+
- Strict mode and its benefits
|
|
44
|
+
- Module resolution strategies
|
|
45
|
+
- Project references for monorepos
|
|
46
|
+
|
|
47
|
+
### 4. Patterns
|
|
48
|
+
- Discriminated unions
|
|
49
|
+
- Branded/nominal types
|
|
50
|
+
- Builder patterns with types
|
|
51
|
+
- Type-safe event systems
|
|
52
|
+
|
|
53
|
+
## Type System Deep Dive
|
|
54
|
+
|
|
55
|
+
### Generic Constraints
|
|
56
|
+
```typescript
|
|
57
|
+
// Good: Constrained generic
|
|
58
|
+
function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
|
|
59
|
+
return obj[key];
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Better: With default
|
|
63
|
+
function merge<T extends object, U extends object = {}>(a: T, b?: U): T & U {
|
|
64
|
+
return { ...a, ...b } as T & U;
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Conditional Types
|
|
69
|
+
```typescript
|
|
70
|
+
// Extract array element type
|
|
71
|
+
type ElementOf<T> = T extends (infer E)[] ? E : never;
|
|
72
|
+
|
|
73
|
+
// Make specific keys optional
|
|
74
|
+
type PartialBy<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
75
|
+
|
|
76
|
+
// Deep partial
|
|
77
|
+
type DeepPartial<T> = T extends object
|
|
78
|
+
? { [P in keyof T]?: DeepPartial<T[P]> }
|
|
79
|
+
: T;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Template Literal Types
|
|
83
|
+
```typescript
|
|
84
|
+
// API route types
|
|
85
|
+
type Method = 'GET' | 'POST' | 'PUT' | 'DELETE';
|
|
86
|
+
type Route = `/api/${string}`;
|
|
87
|
+
type Endpoint = `${Method} ${Route}`;
|
|
88
|
+
|
|
89
|
+
// CSS unit types
|
|
90
|
+
type CSSUnit = 'px' | 'rem' | 'em' | '%';
|
|
91
|
+
type CSSValue = `${number}${CSSUnit}`;
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Discriminated Unions
|
|
95
|
+
```typescript
|
|
96
|
+
// Good: Type-safe state machine
|
|
97
|
+
type State =
|
|
98
|
+
| { status: 'idle' }
|
|
99
|
+
| { status: 'loading' }
|
|
100
|
+
| { status: 'success'; data: Data }
|
|
101
|
+
| { status: 'error'; error: Error };
|
|
102
|
+
|
|
103
|
+
function handleState(state: State) {
|
|
104
|
+
switch (state.status) {
|
|
105
|
+
case 'idle': return renderIdle();
|
|
106
|
+
case 'loading': return renderLoading();
|
|
107
|
+
case 'success': return renderData(state.data); // data is typed!
|
|
108
|
+
case 'error': return renderError(state.error); // error is typed!
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Branded Types
|
|
114
|
+
```typescript
|
|
115
|
+
// Prevent mixing up IDs
|
|
116
|
+
type UserId = string & { readonly brand: unique symbol };
|
|
117
|
+
type OrderId = string & { readonly brand: unique symbol };
|
|
118
|
+
|
|
119
|
+
function createUserId(id: string): UserId {
|
|
120
|
+
return id as UserId;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function getUser(id: UserId): User { /* ... */ }
|
|
124
|
+
function getOrder(id: OrderId): Order { /* ... */ }
|
|
125
|
+
|
|
126
|
+
// Error: Can't pass OrderId where UserId expected
|
|
127
|
+
// getUser(orderId);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Configuration Best Practices
|
|
131
|
+
|
|
132
|
+
### Recommended tsconfig.json
|
|
133
|
+
```json
|
|
134
|
+
{
|
|
135
|
+
"compilerOptions": {
|
|
136
|
+
// Strict mode - always enable
|
|
137
|
+
"strict": true,
|
|
138
|
+
"noUncheckedIndexedAccess": true,
|
|
139
|
+
"noImplicitOverride": true,
|
|
140
|
+
|
|
141
|
+
// Modern output
|
|
142
|
+
"target": "ES2022",
|
|
143
|
+
"module": "ESNext",
|
|
144
|
+
"moduleResolution": "bundler",
|
|
145
|
+
|
|
146
|
+
// Better developer experience
|
|
147
|
+
"esModuleInterop": true,
|
|
148
|
+
"skipLibCheck": true,
|
|
149
|
+
"resolveJsonModule": true,
|
|
150
|
+
|
|
151
|
+
// Source maps for debugging
|
|
152
|
+
"sourceMap": true,
|
|
153
|
+
"declaration": true,
|
|
154
|
+
|
|
155
|
+
// Path aliases
|
|
156
|
+
"baseUrl": ".",
|
|
157
|
+
"paths": {
|
|
158
|
+
"@/*": ["src/*"]
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Strict Flags Explained
|
|
165
|
+
| Flag | Effect | Why Enable |
|
|
166
|
+
|------|--------|------------|
|
|
167
|
+
| `strictNullChecks` | null/undefined checks | Catches null errors |
|
|
168
|
+
| `strictFunctionTypes` | Function param contravariance | Safer callbacks |
|
|
169
|
+
| `strictPropertyInitialization` | Class property init | No uninitialized props |
|
|
170
|
+
| `noImplicitAny` | Explicit any required | No hidden any |
|
|
171
|
+
| `noUncheckedIndexedAccess` | Index access returns undefined | Safer array/object access |
|
|
172
|
+
|
|
173
|
+
## Anti-Patterns to Avoid
|
|
174
|
+
|
|
175
|
+
| Anti-Pattern | Why Bad | Better Approach |
|
|
176
|
+
|--------------|---------|-----------------|
|
|
177
|
+
| `as any` | Defeats type system | Fix the types |
|
|
178
|
+
| `@ts-ignore` | Hides real errors | `@ts-expect-error` with comment |
|
|
179
|
+
| `Function` type | No signature info | Specific function type |
|
|
180
|
+
| `Object` type | Too broad | `Record<string, unknown>` |
|
|
181
|
+
| `{}` for object | Matches primitives too | `Record<string, unknown>` |
|
|
182
|
+
| Nested ternaries in types | Hard to read | Extract to named types |
|
|
183
|
+
|
|
184
|
+
## Type-Safe Patterns
|
|
185
|
+
|
|
186
|
+
### API Response Handling
|
|
187
|
+
```typescript
|
|
188
|
+
type ApiResponse<T> =
|
|
189
|
+
| { success: true; data: T }
|
|
190
|
+
| { success: false; error: { code: string; message: string } };
|
|
191
|
+
|
|
192
|
+
async function fetchApi<T>(url: string): Promise<ApiResponse<T>> {
|
|
193
|
+
try {
|
|
194
|
+
const response = await fetch(url);
|
|
195
|
+
const data = await response.json();
|
|
196
|
+
return { success: true, data };
|
|
197
|
+
} catch (e) {
|
|
198
|
+
return {
|
|
199
|
+
success: false,
|
|
200
|
+
error: { code: 'FETCH_ERROR', message: String(e) }
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Type-Safe Event Emitter
|
|
207
|
+
```typescript
|
|
208
|
+
type EventMap = {
|
|
209
|
+
'user:login': { userId: string };
|
|
210
|
+
'user:logout': { reason?: string };
|
|
211
|
+
'error': { code: number; message: string };
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
class TypedEmitter<T extends Record<string, unknown>> {
|
|
215
|
+
on<K extends keyof T>(event: K, handler: (data: T[K]) => void): void { }
|
|
216
|
+
emit<K extends keyof T>(event: K, data: T[K]): void { }
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const emitter = new TypedEmitter<EventMap>();
|
|
220
|
+
emitter.on('user:login', (data) => {
|
|
221
|
+
console.log(data.userId); // typed!
|
|
222
|
+
});
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
## Performance Optimization
|
|
226
|
+
|
|
227
|
+
### Reduce Type Computation
|
|
228
|
+
- Use interfaces over type aliases for objects (better caching)
|
|
229
|
+
- Avoid deeply nested conditional types
|
|
230
|
+
- Use `type` for unions, `interface` for objects
|
|
231
|
+
- Split large types into smaller ones
|
|
232
|
+
|
|
233
|
+
### IDE Performance
|
|
234
|
+
- Use project references for monorepos
|
|
235
|
+
- Exclude node_modules properly
|
|
236
|
+
- Use `skipLibCheck: true`
|
|
237
|
+
- Keep dependencies up to date
|
|
238
|
+
|
|
239
|
+
## Constraints
|
|
240
|
+
|
|
241
|
+
- Never use `as any` to silence errors
|
|
242
|
+
- Always enable strict mode on new projects
|
|
243
|
+
- Document complex types with comments
|
|
244
|
+
- Prefer inference over explicit annotations
|
|
245
|
+
- Use `unknown` instead of `any` for truly unknown types
|
|
246
|
+
|
|
247
|
+
## Related Skills
|
|
248
|
+
|
|
249
|
+
- `frontend-developer` - TypeScript in React
|
|
250
|
+
- `backend-developer` - Node.js TypeScript
|
|
251
|
+
- `fullstack-developer` - End-to-end type safety
|