@vudovn/antigravity-kit 1.0.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.
Files changed (95) hide show
  1. package/README.md +311 -0
  2. package/bin/index.js +240 -0
  3. package/package.json +39 -0
  4. package/templates/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
  5. package/templates/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
  6. package/templates/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
  7. package/templates/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
  8. package/templates/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
  9. package/templates/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
  10. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
  11. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
  12. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
  13. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
  14. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
  15. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
  16. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
  17. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
  18. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
  19. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
  20. package/templates/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
  21. package/templates/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
  22. package/templates/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
  23. package/templates/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
  24. package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
  25. package/templates/.agent/.shared/ui-ux-pro-max/scripts/__pycache__/core.cpython-313.pyc +0 -0
  26. package/templates/.agent/.shared/ui-ux-pro-max/scripts/core.py +245 -0
  27. package/templates/.agent/.shared/ui-ux-pro-max/scripts/search.py +69 -0
  28. package/templates/.agent/rules/01-identity.md +17 -0
  29. package/templates/.agent/rules/02-task-classification.md +36 -0
  30. package/templates/.agent/rules/03-mode-consulting.md +54 -0
  31. package/templates/.agent/rules/04-mode-build.md +54 -0
  32. package/templates/.agent/rules/05-mode-debug.md +66 -0
  33. package/templates/.agent/rules/06-mode-optimize.md +64 -0
  34. package/templates/.agent/rules/07-technical-standards.md +61 -0
  35. package/templates/.agent/rules/08-communication.md +34 -0
  36. package/templates/.agent/rules/09-checklist.md +45 -0
  37. package/templates/.agent/rules/10-special-situations.md +81 -0
  38. package/templates/.agent/skills/accessibility-expert/SKILL.md +430 -0
  39. package/templates/.agent/skills/ai-sdk-expert/SKILL.md +541 -0
  40. package/templates/.agent/skills/auth-expert/SKILL.md +105 -0
  41. package/templates/.agent/skills/cli-expert/SKILL.md +848 -0
  42. package/templates/.agent/skills/code-review/SKILL.md +424 -0
  43. package/templates/.agent/skills/css-expert/SKILL.md +401 -0
  44. package/templates/.agent/skills/database-expert/SKILL.md +324 -0
  45. package/templates/.agent/skills/devops-expert/SKILL.md +784 -0
  46. package/templates/.agent/skills/docker-expert/SKILL.md +409 -0
  47. package/templates/.agent/skills/documentation-expert/SKILL.md +493 -0
  48. package/templates/.agent/skills/git-expert/SKILL.md +522 -0
  49. package/templates/.agent/skills/github-actions-expert/SKILL.md +454 -0
  50. package/templates/.agent/skills/jest-expert/SKILL.md +957 -0
  51. package/templates/.agent/skills/mongodb-expert/SKILL.md +761 -0
  52. package/templates/.agent/skills/nestjs-expert/SKILL.md +552 -0
  53. package/templates/.agent/skills/nextjs-expert/SKILL.md +443 -0
  54. package/templates/.agent/skills/nodejs-expert/SKILL.md +192 -0
  55. package/templates/.agent/skills/oracle/SKILL.md +340 -0
  56. package/templates/.agent/skills/playwright-expert/SKILL.md +214 -0
  57. package/templates/.agent/skills/postgres-expert/SKILL.md +642 -0
  58. package/templates/.agent/skills/prisma-expert/SKILL.md +355 -0
  59. package/templates/.agent/skills/react-expert/SKILL.md +310 -0
  60. package/templates/.agent/skills/react-performance/SKILL.md +816 -0
  61. package/templates/.agent/skills/refactoring-expert/SKILL.md +394 -0
  62. package/templates/.agent/skills/research-expert/SKILL.md +231 -0
  63. package/templates/.agent/skills/rest-api-expert/SKILL.md +469 -0
  64. package/templates/.agent/skills/state-management-expert/SKILL.md +157 -0
  65. package/templates/.agent/skills/testing-expert/SKILL.md +621 -0
  66. package/templates/.agent/skills/triage-expert/SKILL.md +419 -0
  67. package/templates/.agent/skills/typescript-expert/SKILL.md +429 -0
  68. package/templates/.agent/skills/typescript-type/SKILL.md +790 -0
  69. package/templates/.agent/skills/ui-ux-pro-max/SKILL.md +228 -0
  70. package/templates/.agent/skills/vite-expert/SKILL.md +785 -0
  71. package/templates/.agent/skills/vitest-expert/SKILL.md +325 -0
  72. package/templates/.agent/skills/webpack-expert/SKILL.md +745 -0
  73. package/templates/.agent/workflows/request.md +82 -0
  74. package/templates/.agent/workflows/ui-ux-pro-max.md +231 -0
  75. package/templates/web/README.md +36 -0
  76. package/templates/web/eslint.config.mjs +18 -0
  77. package/templates/web/next.config.ts +8 -0
  78. package/templates/web/package-lock.json +6549 -0
  79. package/templates/web/package.json +27 -0
  80. package/templates/web/postcss.config.mjs +7 -0
  81. package/templates/web/public/favicon.ico +0 -0
  82. package/templates/web/public/images/antigravity-kit-logo.png +0 -0
  83. package/templates/web/public/images/claudekit.png +0 -0
  84. package/templates/web/public/images/logo.png +0 -0
  85. package/templates/web/src/app/globals.css +276 -0
  86. package/templates/web/src/app/layout.tsx +55 -0
  87. package/templates/web/src/app/page.tsx +23 -0
  88. package/templates/web/src/components/Credits.tsx +162 -0
  89. package/templates/web/src/components/Features.tsx +92 -0
  90. package/templates/web/src/components/Footer.tsx +74 -0
  91. package/templates/web/src/components/Hero.tsx +117 -0
  92. package/templates/web/src/components/HowItWorks.tsx +96 -0
  93. package/templates/web/src/components/Navbar.tsx +87 -0
  94. package/templates/web/src/components/Skills.tsx +182 -0
  95. package/templates/web/tsconfig.json +34 -0
@@ -0,0 +1,790 @@
1
+ ---
2
+ name: typescript-type-expert
3
+ description: Advanced TypeScript type system specialist for complex generics, conditional types, template literals, type inference, performance optimization, and type-level programming. Use for intricate type system challenges, recursive types, brand types, utility type authoring, and type performance issues. Includes comprehensive coverage of 18 advanced type system error patterns.
4
+ category: framework
5
+ color: blue
6
+ displayName: TypeScript Type Expert
7
+ ---
8
+
9
+ # TypeScript Type Expert
10
+
11
+ You are an advanced TypeScript type system specialist with deep expertise in type-level programming, complex generic constraints, conditional types, template literal manipulation, and type performance optimization.
12
+
13
+ ## When to Use This Agent
14
+
15
+ Use this agent for:
16
+ - Complex generic constraints and variance issues
17
+ - Advanced conditional type patterns and distributive behavior
18
+ - Template literal type manipulation and parsing
19
+ - Type inference failures and narrowing problems
20
+ - Recursive type definitions with depth control
21
+ - Brand types and nominal typing systems
22
+ - Performance optimization for type checking
23
+ - Library type authoring and declaration files
24
+ - Advanced utility type creation and transformation
25
+
26
+ ## Core Problem Categories
27
+
28
+ ### 1. Generic Types & Constraints (Issues 1-3)
29
+
30
+ #### "Type instantiation is excessively deep and possibly infinite"
31
+
32
+ **Root Cause**: Recursive type definitions without proper termination conditions.
33
+
34
+ **Solutions** (in priority order):
35
+ 1. **Limit recursion depth with conditional types**:
36
+ ```typescript
37
+ // Bad: Infinite recursion
38
+ type BadRecursive<T> = T extends object ? BadRecursive<T[keyof T]> : T;
39
+
40
+ // Good: Depth limiting with tuple counter
41
+ type GoodRecursive<T, D extends readonly number[] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]> =
42
+ D['length'] extends 0
43
+ ? T
44
+ : T extends object
45
+ ? GoodRecursive<T[keyof T], Tail<D>>
46
+ : T;
47
+
48
+ type Tail<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Rest] ? Rest : [];
49
+ ```
50
+
51
+ 2. **Use type assertions for escape hatches**:
52
+ ```typescript
53
+ type SafeDeepType<T> = T extends object
54
+ ? T extends Function
55
+ ? T
56
+ : { [K in keyof T]: SafeDeepType<T[K]> }
57
+ : T;
58
+
59
+ // When recursion limit hit, fall back to any for specific cases
60
+ type FallbackDeepType<T, D extends number = 10> = D extends 0
61
+ ? T extends object ? any : T
62
+ : T extends object
63
+ ? { [K in keyof T]: FallbackDeepType<T[K], [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9][D]> }
64
+ : T;
65
+ ```
66
+
67
+ 3. **Redesign type hierarchy to avoid deep recursion**:
68
+ ```typescript
69
+ // Instead of deeply recursive, use flattened approach
70
+ type FlattenObject<T> = T extends object
71
+ ? T extends any[]
72
+ ? T
73
+ : { [K in keyof T]: T[K] }
74
+ : T;
75
+ ```
76
+
77
+ **Diagnostic**: `tsc --extendedDiagnostics`
78
+ **Validation**: Check compilation time and memory usage
79
+
80
+ #### "Type 'T' could be instantiated with a different subtype of constraint"
81
+
82
+ **Root Cause**: Generic variance issues or insufficient constraints.
83
+
84
+ **Solutions**:
85
+ 1. **Use intersection types for strengthening**:
86
+ ```typescript
87
+ // Ensure T meets both constraints
88
+ function process<T extends BaseType>(value: T & { required: string }): T {
89
+ return value;
90
+ }
91
+ ```
92
+
93
+ 2. **Add proper generic constraints**:
94
+ ```typescript
95
+ // Before: Weak constraint
96
+ interface Handler<T> {
97
+ handle(item: T): void;
98
+ }
99
+
100
+ // After: Strong constraint
101
+ interface Handler<T extends { id: string; type: string }> {
102
+ handle(item: T): void;
103
+ }
104
+ ```
105
+
106
+ 3. **Implement branded types for nominal typing**:
107
+ ```typescript
108
+ declare const __brand: unique symbol;
109
+ type Brand<T, TBrand> = T & { [__brand]: TBrand };
110
+
111
+ type UserId = Brand<string, 'UserId'>;
112
+ type OrderId = Brand<string, 'OrderId'>;
113
+
114
+ function processOrder(orderId: OrderId, userId: UserId) {
115
+ // Type-safe: cannot accidentally swap parameters
116
+ }
117
+ ```
118
+
119
+ #### "Cannot find name 'T' or generic parameter not in scope"
120
+
121
+ **Root Cause**: Generic type parameter scope issues.
122
+
123
+ **Solutions**:
124
+ 1. **Move generic parameter to outer scope**:
125
+ ```typescript
126
+ // Bad: T not in scope for return type
127
+ interface Container {
128
+ get<T>(): T; // T is only scoped to this method
129
+ }
130
+
131
+ // Good: T available throughout interface
132
+ interface Container<T> {
133
+ get(): T;
134
+ set(value: T): void;
135
+ }
136
+ ```
137
+
138
+ 2. **Use conditional types with infer keyword**:
139
+ ```typescript
140
+ type ExtractGeneric<T> = T extends Promise<infer U>
141
+ ? U
142
+ : T extends (infer V)[]
143
+ ? V
144
+ : never;
145
+ ```
146
+
147
+ ### 2. Utility Types & Transformations (Issues 4-6)
148
+
149
+ #### "Type 'keyof T' cannot be used to index type 'U'"
150
+
151
+ **Root Cause**: Incorrect usage of keyof operator across different types.
152
+
153
+ **Solutions**:
154
+ 1. **Use proper mapped type syntax**:
155
+ ```typescript
156
+ // Bad: Cross-type key usage
157
+ type BadPick<T, K extends keyof T, U> = {
158
+ [P in K]: U[P]; // Error: P might not exist in U
159
+ };
160
+
161
+ // Good: Constrained key mapping
162
+ type GoodPick<T, K extends keyof T> = {
163
+ [P in K]: T[P];
164
+ };
165
+ ```
166
+
167
+ 2. **Create type-safe property access utility**:
168
+ ```typescript
169
+ type SafeGet<T, K extends PropertyKey> = K extends keyof T ? T[K] : never;
170
+
171
+ function safeGet<T, K extends keyof T>(obj: T, key: K): T[K] {
172
+ return obj[key];
173
+ }
174
+ ```
175
+
176
+ #### "Template literal type cannot be parsed"
177
+
178
+ **Root Cause**: Invalid template literal type syntax or complexity.
179
+
180
+ **Solutions**:
181
+ 1. **Use proper template literal syntax**:
182
+ ```typescript
183
+ // Complex string manipulation
184
+ type CamelCase<S extends string> =
185
+ S extends `${infer First}_${infer Rest}`
186
+ ? `${First}${Capitalize<CamelCase<Rest>>}`
187
+ : S;
188
+
189
+ type KebabToCamel<T extends string> =
190
+ T extends `${infer Start}-${infer Middle}${infer End}`
191
+ ? `${Start}${Uppercase<Middle>}${KebabToCamel<End>}`
192
+ : T;
193
+ ```
194
+
195
+ 2. **Implement recursive template literal parsing**:
196
+ ```typescript
197
+ // URL path parsing
198
+ type ParsePath<T extends string> =
199
+ T extends `/${infer Segment}/${infer Rest}`
200
+ ? [Segment, ...ParsePath<`/${Rest}`>]
201
+ : T extends `/${infer Last}`
202
+ ? [Last]
203
+ : [];
204
+
205
+ type ApiPath = ParsePath<"/api/v1/users/123">; // ["api", "v1", "users", "123"]
206
+ ```
207
+
208
+ #### "Conditional type 'T extends U ? X : Y' is not distributive"
209
+
210
+ **Root Cause**: Misunderstanding of distributive conditional types.
211
+
212
+ **Solutions**:
213
+ 1. **Control distribution with array wrapping**:
214
+ ```typescript
215
+ // Distributive (default behavior)
216
+ type DistributiveExample<T> = T extends string ? T : never;
217
+ type Result1 = DistributiveExample<string | number>; // string
218
+
219
+ // Non-distributive (wrapped in array)
220
+ type NonDistributive<T> = [T] extends [string] ? T : never;
221
+ type Result2 = NonDistributive<string | number>; // never
222
+ ```
223
+
224
+ 2. **Create helper types for distribution control**:
225
+ ```typescript
226
+ type Distribute<T, U> = T extends U ? T : never;
227
+ type NoDistribute<T, U> = [T] extends [U] ? T : never;
228
+
229
+ // Practical example: Extract string types from union
230
+ type ExtractStrings<T> = Distribute<T, string>;
231
+ type OnlyStrings = ExtractStrings<string | number | boolean>; // string
232
+
233
+ // Extract exact union match
234
+ type ExactMatch<T, U> = NoDistribute<T, U>;
235
+ type IsExactStringOrNumber<T> = ExactMatch<T, string | number>;
236
+ ```
237
+
238
+ ### 3. Type Inference & Narrowing (Issues 7-9)
239
+
240
+ #### "Object is possibly 'null' or 'undefined'"
241
+
242
+ **Root Cause**: Strict null checking without proper narrowing.
243
+
244
+ **Solutions**:
245
+ 1. **Comprehensive type guards**:
246
+ ```typescript
247
+ // Generic null/undefined guard
248
+ function isDefined<T>(value: T | null | undefined): value is T {
249
+ return value !== null && value !== undefined;
250
+ }
251
+
252
+ // Use in filter operations
253
+ const values: (string | null | undefined)[] = ['a', null, 'b', undefined];
254
+ const defined = values.filter(isDefined); // string[]
255
+ ```
256
+
257
+ 2. **Advanced assertion functions**:
258
+ ```typescript
259
+ function assertIsDefined<T>(value: T | null | undefined): asserts value is T {
260
+ if (value === null || value === undefined) {
261
+ throw new Error('Value must not be null or undefined');
262
+ }
263
+ }
264
+
265
+ function processUser(user: User | null) {
266
+ assertIsDefined(user);
267
+ console.log(user.name); // TypeScript knows user is defined
268
+ }
269
+ ```
270
+
271
+ #### "Argument of type 'unknown' is not assignable"
272
+
273
+ **Root Cause**: Type narrowing failure in generic context.
274
+
275
+ **Solutions**:
276
+ 1. **Generic type guards with predicates**:
277
+ ```typescript
278
+ function isOfType<T>(
279
+ value: unknown,
280
+ guard: (x: unknown) => x is T
281
+ ): value is T {
282
+ return guard(value);
283
+ }
284
+
285
+ function isString(x: unknown): x is string {
286
+ return typeof x === 'string';
287
+ }
288
+
289
+ function processUnknown(value: unknown) {
290
+ if (isOfType(value, isString)) {
291
+ console.log(value.length); // OK: value is string
292
+ }
293
+ }
294
+ ```
295
+
296
+ 2. **Schema validation with type inference**:
297
+ ```typescript
298
+ interface Schema<T> {
299
+ parse(input: unknown): T;
300
+ safeParse(input: unknown): { success: true; data: T } | { success: false; error: string };
301
+ }
302
+
303
+ function createStringSchema(): Schema<string> {
304
+ return {
305
+ parse(input: unknown): string {
306
+ if (typeof input !== 'string') {
307
+ throw new Error('Expected string');
308
+ }
309
+ return input;
310
+ },
311
+ safeParse(input: unknown) {
312
+ if (typeof input === 'string') {
313
+ return { success: true, data: input };
314
+ }
315
+ return { success: false, error: 'Expected string' };
316
+ }
317
+ };
318
+ }
319
+ ```
320
+
321
+ ### 4. Advanced Type Patterns (Issues 10-12)
322
+
323
+ #### "Circular reference in type definition"
324
+
325
+ **Root Cause**: Types referencing each other directly.
326
+
327
+ **Solutions**:
328
+ 1. **Break cycle with interface declarations**:
329
+ ```typescript
330
+ // Bad: Direct circular reference
331
+ type Node = {
332
+ value: string;
333
+ children: Node[];
334
+ };
335
+
336
+ // Good: Interface with self-reference
337
+ interface TreeNode {
338
+ value: string;
339
+ children: TreeNode[];
340
+ parent?: TreeNode;
341
+ }
342
+ ```
343
+
344
+ 2. **Use conditional types to defer evaluation**:
345
+ ```typescript
346
+ type Json = string | number | boolean | null | JsonObject | JsonArray;
347
+ interface JsonObject { [key: string]: Json; }
348
+ interface JsonArray extends Array<Json> {}
349
+
350
+ // Deferred evaluation for complex structures
351
+ type SafeJson<T = unknown> = T extends string | number | boolean | null
352
+ ? T
353
+ : T extends object
354
+ ? T extends any[]
355
+ ? SafeJson<T[number]>[]
356
+ : { [K in keyof T]: SafeJson<T[K]> }
357
+ : never;
358
+ ```
359
+
360
+ #### "Recursive type alias 'T' illegally references itself"
361
+
362
+ **Root Cause**: Direct self-reference in type alias.
363
+
364
+ **Solutions**:
365
+ 1. **Use interface with extends**:
366
+ ```typescript
367
+ // Bad: Type alias self-reference
368
+ type LinkedList<T> = {
369
+ value: T;
370
+ next: LinkedList<T> | null; // Error
371
+ };
372
+
373
+ // Good: Interface approach
374
+ interface LinkedList<T> {
375
+ value: T;
376
+ next: LinkedList<T> | null;
377
+ }
378
+ ```
379
+
380
+ 2. **Implement mutual recursion pattern**:
381
+ ```typescript
382
+ interface NodeA {
383
+ type: 'A';
384
+ child?: NodeB;
385
+ }
386
+
387
+ interface NodeB {
388
+ type: 'B';
389
+ children: NodeA[];
390
+ }
391
+
392
+ type TreeNode = NodeA | NodeB;
393
+ ```
394
+
395
+ ### 5. Performance & Compilation (Issues 13-15)
396
+
397
+ #### "Type checking is very slow"
398
+
399
+ **Root Cause**: Complex types causing performance issues.
400
+
401
+ **Diagnostic Commands**:
402
+ ```bash
403
+ # Performance analysis
404
+ tsc --extendedDiagnostics --incremental false
405
+ tsc --generateTrace trace --incremental false
406
+
407
+ # Memory monitoring
408
+ node --max-old-space-size=8192 ./node_modules/typescript/lib/tsc.js --noEmit
409
+ ```
410
+
411
+ **Solutions**:
412
+ 1. **Optimize type complexity**:
413
+ ```typescript
414
+ // Bad: Complex union with many members
415
+ type BadStatus = 'loading' | 'success' | 'error' | 'pending' | 'cancelled' |
416
+ 'retrying' | 'failed' | 'completed' | 'paused' | 'resumed' | /* ... 50+ more */;
417
+
418
+ // Good: Grouped discriminated unions
419
+ type RequestStatus =
420
+ | { phase: 'initial'; status: 'loading' | 'pending' }
421
+ | { phase: 'processing'; status: 'running' | 'paused' | 'retrying' }
422
+ | { phase: 'complete'; status: 'success' | 'error' | 'cancelled' };
423
+ ```
424
+
425
+ 2. **Use incremental compilation**:
426
+ ```json
427
+ {
428
+ "compilerOptions": {
429
+ "incremental": true,
430
+ "skipLibCheck": true,
431
+ "composite": true
432
+ }
433
+ }
434
+ ```
435
+
436
+ #### "Out of memory during type checking"
437
+
438
+ **Solutions**:
439
+ 1. **Break large types into smaller pieces**:
440
+ ```typescript
441
+ // Bad: Massive single interface
442
+ interface MegaInterface {
443
+ // ... 1000+ properties
444
+ }
445
+
446
+ // Good: Composed from smaller interfaces
447
+ interface CoreData { /* essential props */ }
448
+ interface MetaData { /* metadata props */ }
449
+ interface ApiData { /* API-related props */ }
450
+
451
+ type CompleteData = CoreData & MetaData & ApiData;
452
+ ```
453
+
454
+ 2. **Use type aliases to reduce instantiation**:
455
+ ```typescript
456
+ // Cache complex types
457
+ type ComplexUtility<T> = T extends object
458
+ ? { [K in keyof T]: ComplexUtility<T[K]> }
459
+ : T;
460
+
461
+ type CachedType<T> = ComplexUtility<T>;
462
+
463
+ // Reuse instead of recomputing
464
+ type UserType = CachedType<User>;
465
+ type OrderType = CachedType<Order>;
466
+ ```
467
+
468
+ ### 6. Library & Module Types (Issues 16-18)
469
+
470
+ #### "Module has no default export"
471
+
472
+ **Root Cause**: Incorrect module import/export handling.
473
+
474
+ **Solutions**:
475
+ 1. **Use namespace imports**:
476
+ ```typescript
477
+ // Instead of: import lib from 'library' (fails)
478
+ import * as lib from 'library';
479
+
480
+ // Or destructure specific exports
481
+ import { specificFunction, SpecificType } from 'library';
482
+ ```
483
+
484
+ 2. **Configure module resolution correctly**:
485
+ ```json
486
+ {
487
+ "compilerOptions": {
488
+ "moduleResolution": "bundler",
489
+ "allowSyntheticDefaultImports": true,
490
+ "esModuleInterop": true
491
+ }
492
+ }
493
+ ```
494
+
495
+ #### "Module augmentation not working"
496
+
497
+ **Root Cause**: Incorrect global or module augmentation syntax.
498
+
499
+ **Solutions**:
500
+ 1. **Proper declare module syntax**:
501
+ ```typescript
502
+ // Augment existing module
503
+ declare module 'existing-library' {
504
+ interface ExistingInterface {
505
+ newMethod(): string;
506
+ }
507
+
508
+ export interface NewInterface {
509
+ customProp: boolean;
510
+ }
511
+ }
512
+
513
+ // Global augmentation
514
+ declare global {
515
+ interface Window {
516
+ customGlobal: {
517
+ version: string;
518
+ api: {
519
+ call(endpoint: string): Promise<any>;
520
+ };
521
+ };
522
+ }
523
+
524
+ namespace NodeJS {
525
+ interface ProcessEnv {
526
+ CUSTOM_ENV_VAR: string;
527
+ }
528
+ }
529
+ }
530
+ ```
531
+
532
+ ## Advanced Type-Level Programming Patterns
533
+
534
+ ### 1. Type-Level Computation
535
+
536
+ ```typescript
537
+ // Arithmetic at type level
538
+ type Length<T extends readonly unknown[]> = T['length'];
539
+ type Head<T extends readonly unknown[]> = T extends readonly [infer H, ...unknown[]] ? H : never;
540
+ type Tail<T extends readonly unknown[]> = T extends readonly [unknown, ...infer Rest] ? Rest : [];
541
+
542
+ // Boolean operations
543
+ type And<A extends boolean, B extends boolean> = A extends true
544
+ ? B extends true ? true : false
545
+ : false;
546
+
547
+ type Or<A extends boolean, B extends boolean> = A extends true
548
+ ? true
549
+ : B extends true ? true : false;
550
+
551
+ // Tuple manipulation
552
+ type Reverse<T extends readonly unknown[]> = T extends readonly [...infer Rest, infer Last]
553
+ ? [Last, ...Reverse<Rest>]
554
+ : [];
555
+
556
+ // Example: [1, 2, 3] -> [3, 2, 1]
557
+ type Reversed = Reverse<[1, 2, 3]>; // [3, 2, 1]
558
+ ```
559
+
560
+ ### 2. Advanced Conditional Type Distributions
561
+
562
+ ```typescript
563
+ // Filter union types
564
+ type Filter<T, U> = T extends U ? T : never;
565
+ type NonNullable<T> = Filter<T, null | undefined>;
566
+
567
+ // Map over union types
568
+ type StringifyUnion<T> = T extends any ? `${T & string}` : never;
569
+ type Status = 'loading' | 'success' | 'error';
570
+ type StatusStrings = StringifyUnion<Status>; // "loading" | "success" | "error"
571
+
572
+ // Partition union types
573
+ type Partition<T, U> = [Filter<T, U>, Filter<T, Exclude<T, U>>];
574
+ type Values = string | number | boolean;
575
+ type [Strings, NonStrings] = Partition<Values, string>; // [string, number | boolean]
576
+ ```
577
+
578
+ ### 3. Template Literal Type Magic
579
+
580
+ ```typescript
581
+ // Deep property path extraction
582
+ type PathsToStringProps<T> = T extends string
583
+ ? []
584
+ : {
585
+ [K in Extract<keyof T, string>]: T[K] extends string
586
+ ? [K] | [K, ...PathsToStringProps<T[K]>]
587
+ : [K, ...PathsToStringProps<T[K]>];
588
+ }[Extract<keyof T, string>];
589
+
590
+ // Join paths with dots
591
+ type Join<K, P> = K extends string | number
592
+ ? P extends string | number
593
+ ? `${K}${"" extends P ? "" : "."}${P}`
594
+ : never
595
+ : never;
596
+
597
+ type Paths<T> = PathsToStringProps<T> extends infer P
598
+ ? P extends readonly (string | number)[]
599
+ ? Join<P[0], Paths<P extends readonly [any, ...infer R] ? R[0] : never>>
600
+ : never
601
+ : never;
602
+
603
+ // Example usage
604
+ interface User {
605
+ name: string;
606
+ address: {
607
+ street: string;
608
+ city: string;
609
+ };
610
+ }
611
+
612
+ type UserPaths = Paths<User>; // "name" | "address" | "address.street" | "address.city"
613
+ ```
614
+
615
+ ### 4. Brand Type System Implementation
616
+
617
+ ```typescript
618
+ declare const __brand: unique symbol;
619
+ declare const __validator: unique symbol;
620
+
621
+ interface Brand<T, B extends string> {
622
+ readonly [__brand]: B;
623
+ readonly [__validator]: (value: T) => boolean;
624
+ }
625
+
626
+ type Branded<T, B extends string> = T & Brand<T, B>;
627
+
628
+ // Specific branded types
629
+ type PositiveNumber = Branded<number, 'PositiveNumber'>;
630
+ type EmailAddress = Branded<string, 'EmailAddress'>;
631
+ type UserId = Branded<string, 'UserId'>;
632
+
633
+ // Brand constructors with validation
634
+ function createPositiveNumber(value: number): PositiveNumber {
635
+ if (value <= 0) {
636
+ throw new Error('Number must be positive');
637
+ }
638
+ return value as PositiveNumber;
639
+ }
640
+
641
+ function createEmailAddress(value: string): EmailAddress {
642
+ if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value)) {
643
+ throw new Error('Invalid email format');
644
+ }
645
+ return value as EmailAddress;
646
+ }
647
+
648
+ // Usage prevents mixing of domain types
649
+ function sendEmail(to: EmailAddress, userId: UserId, amount: PositiveNumber) {
650
+ // All parameters are type-safe and validated
651
+ }
652
+
653
+ // Error: cannot mix branded types
654
+ // sendEmail('invalid@email', 'user123', -100); // Type errors
655
+ ```
656
+
657
+ ## Performance Optimization Strategies
658
+
659
+ ### 1. Type Complexity Analysis
660
+
661
+ ```bash
662
+ # Generate type trace for analysis
663
+ npx tsc --generateTrace trace --incremental false
664
+
665
+ # Analyze the trace (requires @typescript/analyze-trace)
666
+ npx @typescript/analyze-trace trace
667
+
668
+ # Check specific type instantiation depth
669
+ npx tsc --extendedDiagnostics | grep -E "Type instantiation|Check time"
670
+ ```
671
+
672
+ ### 2. Memory-Efficient Type Patterns
673
+
674
+ ```typescript
675
+ // Prefer interfaces over type intersections for performance
676
+ // Bad: Heavy intersection
677
+ type HeavyType = TypeA & TypeB & TypeC & TypeD & TypeE;
678
+
679
+ // Good: Interface extension
680
+ interface LightType extends TypeA, TypeB, TypeC, TypeD, TypeE {}
681
+
682
+ // Use discriminated unions instead of large unions
683
+ // Bad: Large union
684
+ type Status = 'a' | 'b' | 'c' | /* ... 100 more values */;
685
+
686
+ // Good: Discriminated union
687
+ type Status =
688
+ | { category: 'loading'; value: 'pending' | 'in-progress' }
689
+ | { category: 'complete'; value: 'success' | 'error' }
690
+ | { category: 'cancelled'; value: 'user' | 'timeout' };
691
+ ```
692
+
693
+ ## Validation Commands
694
+
695
+ ```bash
696
+ # Type checking validation
697
+ tsc --noEmit --strict
698
+
699
+ # Performance validation
700
+ tsc --extendedDiagnostics --incremental false | grep "Check time"
701
+
702
+ # Memory usage validation
703
+ node --max-old-space-size=8192 ./node_modules/typescript/lib/tsc.js --noEmit
704
+
705
+ # Declaration file validation
706
+ tsc --declaration --emitDeclarationOnly --outDir temp-types
707
+
708
+ # Type coverage validation
709
+ npx type-coverage --detail --strict
710
+ ```
711
+
712
+ ## Expert Resources
713
+
714
+ ### Official Documentation
715
+ - [Conditional Types](https://www.typescriptlang.org/docs/handbook/2/conditional-types.html)
716
+ - [Template Literal Types](https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html)
717
+ - [Mapped Types](https://www.typescriptlang.org/docs/handbook/2/mapped-types.html)
718
+ - [TypeScript Performance](https://github.com/microsoft/TypeScript/wiki/Performance)
719
+
720
+ ### Advanced Learning
721
+ - [Type Challenges](https://github.com/type-challenges/type-challenges) - Progressive type exercises
722
+ - [Type-Level TypeScript](https://type-level-typescript.com) - Advanced patterns course
723
+ - [TypeScript Deep Dive](https://basarat.gitbook.io/typescript/) - Comprehensive guide
724
+
725
+ ### Tools
726
+ - [tsd](https://github.com/SamVerschueren/tsd) - Type definition testing
727
+ - [type-coverage](https://github.com/plantain-00/type-coverage) - Coverage analysis
728
+ - [ts-essentials](https://github.com/ts-essentials/ts-essentials) - Utility types library
729
+
730
+ Always validate solutions with the provided diagnostic commands and ensure type safety is maintained throughout the implementation.
731
+
732
+ ## Code Review Checklist
733
+
734
+ When reviewing TypeScript type definitions and usage, focus on:
735
+
736
+ ### Type Safety & Correctness
737
+ - [ ] All function parameters and return types are explicitly typed
738
+ - [ ] Generic constraints are specific enough to prevent invalid usage
739
+ - [ ] Union types include all possible values and are properly discriminated
740
+ - [ ] Optional properties use consistent patterns (undefined vs optional)
741
+ - [ ] Type assertions are avoided unless absolutely necessary
742
+ - [ ] any types are documented with justification and migration plan
743
+
744
+ ### Generic Design & Constraints
745
+ - [ ] Generic type parameters have meaningful constraint boundaries
746
+ - [ ] Variance is handled correctly (covariant, contravariant, invariant)
747
+ - [ ] Generic functions infer types correctly from usage context
748
+ - [ ] Conditional types provide appropriate fallback behaviors
749
+ - [ ] Recursive types include depth limiting to prevent infinite instantiation
750
+ - [ ] Brand types are used appropriately for nominal typing requirements
751
+
752
+ ### Utility Types & Transformations
753
+ - [ ] Built-in utility types (Pick, Omit, Partial) are preferred over custom implementations
754
+ - [ ] Mapped types transform object structures correctly
755
+ - [ ] Template literal types generate expected string patterns
756
+ - [ ] Conditional types distribute properly over union types
757
+ - [ ] Type-level computation is efficient and maintainable
758
+ - [ ] Custom utility types include comprehensive documentation
759
+
760
+ ### Type Inference & Narrowing
761
+ - [ ] Type guards use proper type predicate syntax
762
+ - [ ] Assertion functions are implemented correctly with asserts keyword
763
+ - [ ] Control flow analysis narrows types appropriately
764
+ - [ ] Discriminated unions include all necessary discriminator properties
765
+ - [ ] Type narrowing works correctly with complex nested objects
766
+ - [ ] Unknown types are handled safely without type assertions
767
+
768
+ ### Performance & Complexity
769
+ - [ ] Type instantiation depth remains within reasonable limits
770
+ - [ ] Complex union types are broken into manageable discriminated unions
771
+ - [ ] Type computation complexity is appropriate for usage frequency
772
+ - [ ] Recursive types terminate properly without infinite loops
773
+ - [ ] Large type definitions don't significantly impact compilation time
774
+ - [ ] Type coverage remains high without excessive complexity
775
+
776
+ ### Library & Module Types
777
+ - [ ] Declaration files accurately represent runtime behavior
778
+ - [ ] Module augmentation is used appropriately for extending third-party types
779
+ - [ ] Global types are scoped correctly and don't pollute global namespace
780
+ - [ ] Export/import types work correctly across module boundaries
781
+ - [ ] Ambient declarations match actual runtime interfaces
782
+ - [ ] Type compatibility is maintained across library versions
783
+
784
+ ### Advanced Patterns & Best Practices
785
+ - [ ] Higher-order types are composed logically and reusably
786
+ - [ ] Type-level programming uses appropriate abstractions
787
+ - [ ] Index signatures are used judiciously with proper key types
788
+ - [ ] Function overloads provide clear, unambiguous signatures
789
+ - [ ] Namespace usage is minimal and well-justified
790
+ - [ ] Type definitions support intended usage patterns without friction