vibes-plug 1.0.0 → 2.11.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.
Files changed (183) hide show
  1. package/.claude/rules/vibes-plug-core.md +32 -0
  2. package/.cursor/rules/vibes-plug-core.mdc +51 -0
  3. package/.cursorrules +42 -0
  4. package/AGENTS.md +96 -0
  5. package/BLUEPRINT.md +309 -125
  6. package/CHANGELOG.md +183 -1
  7. package/CLAUDE.md +70 -0
  8. package/LICENSE +1 -1
  9. package/README.md +641 -263
  10. package/index.js +19 -0
  11. package/package.json +61 -25
  12. package/plugin.json +24 -7
  13. package/scripts/generate_swarm_gif.py +295 -0
  14. package/scripts/install.js +201 -0
  15. package/skills/accessibility-testing-expert/SKILL.md +116 -0
  16. package/skills/ai-cost-token-optimizer/SKILL.md +82 -0
  17. package/skills/ai-evals-benchmark-expert/SKILL.md +188 -0
  18. package/skills/ai-llm-integration-expert/SKILL.md +147 -122
  19. package/skills/ai-media-generation-expert/SKILL.md +172 -0
  20. package/skills/ai-prompt-engineering-expert/SKILL.md +84 -0
  21. package/skills/angular-expert/SKILL.md +148 -0
  22. package/skills/api-design-expert/SKILL.md +316 -309
  23. package/skills/api-gateway-proxy-expert/SKILL.md +81 -0
  24. package/skills/app-analyzer-optimizer/SKILL.md +195 -188
  25. package/skills/apple-ecosystem-expert/SKILL.md +145 -0
  26. package/skills/{asisten_ramah → asisten-ramah}/SKILL.md +7 -1
  27. package/skills/astro-framework-expert/SKILL.md +200 -0
  28. package/skills/async-queue-temporal-expert/SKILL.md +240 -0
  29. package/skills/authentication-identity-expert/SKILL.md +279 -45
  30. package/skills/auto-doc-updater/SKILL.md +219 -203
  31. package/skills/autonomous-chaos-monkey/SKILL.md +63 -0
  32. package/skills/autonomous-red-teamer/SKILL.md +203 -0
  33. package/skills/autonomous-tdd-debugger/SKILL.md +71 -0
  34. package/skills/background-jobs-queue-expert/SKILL.md +235 -0
  35. package/skills/biome-linter-formatter-expert/SKILL.md +89 -0
  36. package/skills/blockchain-web3-expert/SKILL.md +115 -0
  37. package/skills/bootstrap-to-modern/SKILL.md +93 -86
  38. package/skills/brainstorming/SKILL.md +381 -353
  39. package/skills/browser-automation-expert/SKILL.md +222 -0
  40. package/skills/bun-runtime-expert/SKILL.md +7 -1
  41. package/skills/chatbot-messaging-expert/SKILL.md +114 -0
  42. package/skills/ci-cd-devops-architect/SKILL.md +81 -45
  43. package/skills/cloud-hosting-expert/SKILL.md +249 -243
  44. package/skills/coderabbit/SKILL.md +197 -191
  45. package/skills/compliance-gdpr-privacy-expert/SKILL.md +85 -0
  46. package/skills/cron-scheduler-expert/SKILL.md +304 -0
  47. package/skills/data-pipeline-etl-expert/SKILL.md +84 -0
  48. package/skills/data-telemetry-expert/SKILL.md +218 -212
  49. package/skills/data-visualization-expert/SKILL.md +154 -0
  50. package/skills/database-migration-versioning-expert/SKILL.md +90 -0
  51. package/skills/database-orm-expert/SKILL.md +303 -293
  52. package/skills/dependency-upgrade-migrator/SKILL.md +301 -0
  53. package/skills/design-system-architect/SKILL.md +278 -242
  54. package/skills/desktop-electron-expert/SKILL.md +128 -0
  55. package/skills/documentation-site-expert/SKILL.md +59 -0
  56. package/skills/doku-mcp-server/SKILL.md +257 -0
  57. package/skills/doku-payment-gateway/SKILL.md +233 -0
  58. package/skills/domain-driven-design-expert/SKILL.md +82 -0
  59. package/skills/e2e-testing-expert/SKILL.md +320 -314
  60. package/skills/ecommerce-expert/SKILL.md +87 -0
  61. package/skills/edge-serverless-db-expert/SKILL.md +99 -0
  62. package/skills/email-notification-expert/SKILL.md +368 -0
  63. package/skills/error-resilience-expert/SKILL.md +486 -0
  64. package/skills/event-driven-architect/SKILL.md +86 -80
  65. package/skills/feature-flag-analytics-expert/SKILL.md +66 -0
  66. package/skills/file-upload-media-expert/SKILL.md +437 -0
  67. package/skills/firebase-security-expert/SKILL.md +7 -1
  68. package/skills/form-validation-expert/SKILL.md +407 -0
  69. package/skills/fullstack-expert/SKILL.md +260 -201
  70. package/skills/fullstack-expert/references/api_design_guide.md +466 -466
  71. package/skills/fullstack-expert/references/multi_language_backend.md +528 -528
  72. package/skills/fullstack-expert/scripts/api_contract_validator.py +253 -253
  73. package/skills/fullstack-expert/scripts/architecture_analyzer.py +326 -326
  74. package/skills/gemini-agent-booster/SKILL.md +142 -104
  75. package/skills/geospatial-maps-expert/SKILL.md +80 -0
  76. package/skills/global-a11y-i18n-expert/SKILL.md +86 -80
  77. package/skills/glsl-shader-expert/SKILL.md +107 -0
  78. package/skills/go-programming-expert/SKILL.md +300 -294
  79. package/skills/graph-rag-knowledge-expert/SKILL.md +159 -0
  80. package/skills/graphql-apollo-expert/SKILL.md +114 -0
  81. package/skills/headless-cms-expert/SKILL.md +181 -0
  82. package/skills/hig/SKILL.md +193 -187
  83. package/skills/js-backend-expert/SKILL.md +218 -191
  84. package/skills/legacy-code-translator/SKILL.md +71 -0
  85. package/skills/local-slm-edge-ai-expert/SKILL.md +167 -0
  86. package/skills/logging-error-tracking-expert/SKILL.md +344 -0
  87. package/skills/mcp-client-orchestrator/SKILL.md +76 -0
  88. package/skills/mcp-server-architect/SKILL.md +226 -126
  89. package/skills/micro-frontend-architect/SKILL.md +112 -0
  90. package/skills/mobile-expo-expert/SKILL.md +191 -185
  91. package/skills/mobile-push-notification-expert/SKILL.md +71 -0
  92. package/skills/modern-css-native-expert/SKILL.md +189 -0
  93. package/skills/monday-design-aesthetic/SKILL.md +72 -66
  94. package/skills/monorepo-architect/SKILL.md +232 -226
  95. package/skills/mpa-orchestrator/SKILL.md +120 -101
  96. package/skills/multi-agent-orchestration/SKILL.md +173 -153
  97. package/skills/multiple-entry-points/SKILL.md +91 -55
  98. package/skills/mvc-expert/SKILL.md +237 -231
  99. package/skills/n8n-automation-expert/SKILL.md +89 -0
  100. package/skills/nextjs-app-router-expert/SKILL.md +148 -0
  101. package/skills/openapi-swagger-codegen-expert/SKILL.md +67 -0
  102. package/skills/payment-gateway-expert/SKILL.md +129 -45
  103. package/skills/pdf-document-generation-expert/SKILL.md +91 -0
  104. package/skills/performance-web-vitals/SKILL.md +337 -331
  105. package/skills/post-quantum-crypto-migrator/SKILL.md +57 -0
  106. package/skills/prd-architect/SKILL.md +206 -190
  107. package/skills/proactive-background-watcher/SKILL.md +68 -0
  108. package/skills/production-ready-hardener/PRODUCTION_READINESS_REPORT.md +67 -0
  109. package/skills/production-ready-hardener/SKILL.md +461 -468
  110. package/skills/production-ready-hardener/references/production_checklist.md +161 -161
  111. package/skills/production-ready-hardener/scripts/production_readiness_scanner.py +881 -875
  112. package/skills/project-context-mapper/SKILL.md +85 -0
  113. package/skills/pwa-offline-first-expert/SKILL.md +185 -0
  114. package/skills/python-programming-expert/SKILL.md +407 -270
  115. package/skills/rate-limit-abuse-prevention/SKILL.md +377 -0
  116. package/skills/realtime-collaboration-expert/SKILL.md +99 -45
  117. package/skills/rich-text-editor-expert/SKILL.md +177 -0
  118. package/skills/rust-programming-expert/SKILL.md +240 -234
  119. package/skills/saas-billing/SKILL.md +382 -376
  120. package/skills/saas-multi-tenant/SKILL.md +256 -236
  121. package/skills/saas-mvp-launcher/SKILL.md +30 -1
  122. package/skills/saas-transformer/SKILL.md +499 -445
  123. package/skills/saas-transformer/references/billing_integration_guide.md +401 -401
  124. package/skills/saas-transformer/references/feature_gating_patterns.md +137 -137
  125. package/skills/saas-transformer/references/saas_transformation_checklist.md +121 -121
  126. package/skills/saas-transformer/scripts/saas_transformation_scanner.py +39 -29
  127. package/skills/scalability-clean-code/SKILL.md +234 -228
  128. package/skills/search-engine-expert/SKILL.md +89 -0
  129. package/skills/secure-fuzz-testing/SKILL.md +7 -1
  130. package/skills/self-evolving-memory-graph/SKILL.md +91 -0
  131. package/skills/self-healing-cloud-orchestrator/SKILL.md +57 -0
  132. package/skills/senior-frontend/SKILL.md +85 -105
  133. package/skills/seo/SKILL.md +258 -224
  134. package/skills/session-context-loader/SKILL.md +83 -0
  135. package/skills/session-handoff-resume/SKILL.md +163 -157
  136. package/skills/{skill_baru → skill-baru}/SKILL.md +177 -146
  137. package/skills/solidjs-expert/SKILL.md +80 -0
  138. package/skills/spa-orchestrator/SKILL.md +306 -287
  139. package/skills/sse-websocket-streaming-expert/SKILL.md +93 -0
  140. package/skills/state-management-expert/SKILL.md +277 -271
  141. package/skills/supabase-migration/SKILL.md +47 -1
  142. package/skills/supabase-security-expert/SKILL.md +248 -242
  143. package/skills/svelte-sveltekit-expert/SKILL.md +91 -0
  144. package/skills/svg-animation-motion-expert/SKILL.md +115 -0
  145. package/skills/tailwind-expert/SKILL.md +139 -187
  146. package/skills/tanstack-query-expert/SKILL.md +204 -198
  147. package/skills/tauri-expert/SKILL.md +7 -1
  148. package/skills/token-saver/SKILL.md +118 -110
  149. package/skills/typescript-expert/SKILL.md +329 -278
  150. package/skills/ui-components-expert/SKILL.md +166 -63
  151. package/skills/ui-ux-pro-max/SKILL.md +221 -200
  152. package/skills/vector-db-rag-expert/SKILL.md +208 -0
  153. package/skills/vibe-code-gardener/SKILL.md +180 -172
  154. package/skills/visual-qa-vision-agent/SKILL.md +71 -0
  155. package/skills/voice-ai-realtime-agent/SKILL.md +202 -0
  156. package/skills/vue-frontend-expert/SKILL.md +132 -0
  157. package/skills/wasm-edge-computing-expert/SKILL.md +97 -0
  158. package/skills/web-3d-graphics-expert/SKILL.md +137 -0
  159. package/skills/web-game-engine-expert/SKILL.md +102 -0
  160. package/skills/web-scraper/SKILL.md +98 -146
  161. package/skills/website-design-cloner/SKILL.md +180 -0
  162. package/skills/webxr-ar-vr-expert/SKILL.md +123 -0
  163. package/skills/wordpress-headless-expert/SKILL.md +144 -0
  164. package/skills/zero-to-prod-orchestrator/SKILL.md +231 -180
  165. package/skills/zero-trust-secret-vault/SKILL.md +88 -0
  166. package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
  167. package/CONTRIBUTING.md +0 -199
  168. package/SECURITY.md +0 -21
  169. package/banner.png +0 -0
  170. package/skills/senior-fullstack/SKILL.md +0 -167
  171. package/skills/senior-fullstack/references/architecture_patterns.md +0 -160
  172. package/skills/senior-fullstack/references/development_workflows.md +0 -222
  173. package/skills/senior-fullstack/references/tech_stack_guide.md +0 -190
  174. package/skills/senior-fullstack/scripts/code_quality_analyzer.py +0 -114
  175. package/skills/senior-fullstack/scripts/fullstack_scaffolder.py +0 -114
  176. package/skills/senior-fullstack/scripts/project_scaffolder.py +0 -114
  177. package/skills/seo-aeo-landing-page-writer/SKILL.md +0 -97
  178. package/skills/seo-geo/SKILL.md +0 -188
  179. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-310.pyc +0 -0
  180. package/skills/ui-ux-pro-max/scripts/__pycache__/core.cpython-312.pyc +0 -0
  181. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-310.pyc +0 -0
  182. package/skills/ui-ux-pro-max/scripts/__pycache__/design_system.cpython-312.pyc +0 -0
  183. package/skills/ui_ux_expert/SKILL.md +0 -114
@@ -1,279 +1,330 @@
1
- ---
2
- name: typescript-expert
3
- description: "Expert guide for TypeScript 5.x advanced type system, strict mode, generics, utility types, branded types, and type-safe architectural patterns / Panduan ahli untuk sistem tipe TypeScript 5.x, mode strict, generics, utility types, branded types, dan pola arsitektur type-safe."
1
+ ---
2
+ name: typescript-expert
3
+ description: "Expert guide for TypeScript 5.8+ advanced type system, strict mode, generics, utility types, branded types, inferred type predicates, isolated declarations, and type-safe architectural patterns / Panduan ahli untuk sistem tipe TypeScript 5.8+, mode strict, generics, utility types, branded types, inferred type predicates, isolated declarations, dan pola arsitektur type-safe."
4
4
  author: "Roedy Rustam"
5
- ---
6
-
7
- # TypeScript Expert (TypeScript 5.x Edition)
8
-
9
- [English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
10
-
11
- ---
12
-
13
- <a name="english"></a>
14
- ## English
15
-
16
- ### Description
17
- Expert-level TypeScript development covering the advanced type system, strict mode enforcement, generic programming, utility types, branded types, and type-safe patterns for production applications. Targets **TypeScript 5.4+** features including `NoInfer`, `using` declarations, variadic tuple improvements, and `const` type parameters.
18
-
19
- ### Trigger Conditions
20
- - Writing TypeScript with advanced generic constraints.
21
- - Enforcing strict type safety in existing codebases.
22
- - Designing type-safe API contracts (REST, tRPC, Zod schemas).
23
- - Implementing branded types for domain modeling.
24
- - Resolving complex type errors or `any` pollution.
25
- - Setting up `tsconfig.json` for strict projects.
26
- - Writing TypeScript utility types or type helpers.
27
-
28
- ---
29
-
30
- ### TypeScript 5.x — Key Features
31
-
32
- #### `using` Declarations (Explicit Resource Management, TS 5.2)
33
- ```typescript
34
- // Automatically calls [Symbol.dispose] on scope exit
35
- function processFile(path: string) {
36
- using handle = openFile(path); // disposed when function exits
37
- handle.write('data');
38
- }
39
-
40
- // Async version with [Symbol.asyncDispose]
41
- async function processDatabase() {
42
- await using conn = await getConnection();
43
- await conn.query('SELECT 1');
44
- } // conn.close() called automatically
45
- ```
46
-
47
- #### `NoInfer<T>` Utility Type (TS 5.4)
48
- ```typescript
49
- // Prevents unintended type widening in generic inference
50
- function createState<T>(initial: T, fallback: NoInfer<T>): T {
51
- return initial ?? fallback;
52
- }
53
-
54
- // TS now errors if fallback type doesn't match initial
55
- createState('hello', 42); // Error: Argument of type 'number' is not assignable to type 'string'
56
- ```
57
-
58
- #### `const` Type Parameters (TS 5.0)
59
- ```typescript
60
- // Infer literal types from generic arguments
61
- function identity<const T>(value: T): T { return value; }
62
-
63
- const a = identity(['a', 'b', 'c']); // type: readonly ["a", "b", "c"]
64
- const b = identity({ x: 10 }); // type: { readonly x: 10 }
65
- ```
66
-
67
- ---
68
-
69
- ### Strict Mode Configuration
70
-
71
- ```json
72
- // tsconfig.json recommended strict config for production
73
- {
74
- "compilerOptions": {
75
- "target": "ES2022",
76
- "lib": ["ES2022", "DOM"],
77
- "module": "NodeNext",
78
- "moduleResolution": "NodeNext",
79
- "strict": true,
80
- "noUncheckedIndexedAccess": true,
81
- "exactOptionalPropertyTypes": true,
82
- "noImplicitReturns": true,
83
- "noFallthroughCasesInSwitch": true,
84
- "noImplicitOverride": true,
85
- "forceConsistentCasingInFileNames": true,
86
- "isolatedModules": true,
87
- "verbatimModuleSyntax": true,
88
- "skipLibCheck": false
89
- }
90
- }
91
- ```
92
-
93
- ---
94
-
95
- ### Advanced Type Patterns
96
-
97
- #### Branded Types for Domain Modeling
98
- ```typescript
99
- // Prevent mixing semantically different primitives
100
- type Brand<T, B extends string> = T & { readonly __brand: B };
101
-
102
- type UserId = Brand<string, 'UserId'>;
103
- type PostId = Brand<string, 'PostId'>;
104
- type Email = Brand<string, 'Email'>;
105
-
106
- // Constructor functions with validation
107
- function createUserId(id: string): UserId {
108
- if (!id.startsWith('user_')) throw new Error('Invalid user ID format');
109
- return id as UserId;
110
- }
111
-
112
- function getUser(id: UserId): Promise<User> { /* ... */ }
113
-
114
- const postId = 'post_abc' as PostId;
115
- getUser(postId); // Compile error: PostId is not assignable to UserId
116
- ```
117
-
118
- #### Discriminated Unions for State Machines
119
- ```typescript
120
- type ApiState<T> =
121
- | { status: 'idle' }
122
- | { status: 'loading' }
123
- | { status: 'success'; data: T }
124
- | { status: 'error'; error: Error };
125
-
126
- function render<T>(state: ApiState<T>) {
127
- switch (state.status) {
128
- case 'idle': return 'Idle';
129
- case 'loading': return 'Loading...';
130
- case 'success': return `Data: ${JSON.stringify(state.data)}`;
131
- case 'error': return `Error: ${state.error.message}`;
132
- // TypeScript enforces exhaustive matching
133
- }
134
- }
135
- ```
136
-
137
- #### Template Literal Types
138
- ```typescript
139
- type EventName = 'click' | 'focus' | 'blur';
140
- type HandlerName = `on${Capitalize<EventName>}`;
141
- // Result: 'onClick' | 'onFocus' | 'onBlur'
142
-
143
- type DeepReadonly<T> = {
144
- readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
145
- };
146
-
147
- type Paths<T, Prefix extends string = ''> = {
148
- [K in keyof T & string]: T[K] extends object
149
- ? Paths<T[K], `${Prefix}${K}.`>
150
- : `${Prefix}${K}`;
151
- }[keyof T & string];
152
-
153
- // Paths<{ user: { name: string; age: number } }> = "user.name" | "user.age"
154
- ```
155
-
156
- #### Conditional Types and `infer`
157
- ```typescript
158
- type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
159
- type ArrayElement<T> = T extends (infer U)[] ? U : never;
160
- type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
161
-
162
- // Extract function parameter types
163
- type Parameters<T extends (...args: any) => any> =
164
- T extends (...args: infer P) => any ? P : never;
165
- ```
166
-
167
- ---
168
-
169
- ### Type-Safe Patterns
170
-
171
- #### Zod Schema + TypeScript Integration
172
- ```typescript
173
- import { z } from 'zod';
174
-
175
- const UserSchema = z.object({
176
- id: z.string().cuid(),
177
- email: z.string().email(),
178
- role: z.enum(['USER', 'ADMIN']),
179
- createdAt: z.coerce.date(),
180
- });
181
-
182
- type User = z.infer<typeof UserSchema>; // Derive type from schema
183
-
184
- // Type-safe parsing with error handling
185
- function parseUser(data: unknown): User {
186
- return UserSchema.parse(data); // throws ZodError on failure
187
- }
188
-
189
- const safeResult = UserSchema.safeParse(data);
190
- if (safeResult.success) {
191
- console.log(safeResult.data.email); // fully typed
192
- }
193
- ```
194
-
195
- #### Type-Safe Environment Variables
196
- ```typescript
197
- // env.ts — validate env at startup
198
- import { z } from 'zod';
199
-
200
- const envSchema = z.object({
201
- DATABASE_URL: z.string().url(),
202
- NEXTAUTH_SECRET: z.string().min(32),
203
- NODE_ENV: z.enum(['development', 'test', 'production']),
204
- PORT: z.coerce.number().default(3000),
205
- });
206
-
207
- export const env = envSchema.parse(process.env);
208
- // env.PORT is now type `number`, not `string | undefined`
209
- ```
210
-
211
- #### Generic Repository Pattern
212
- ```typescript
213
- interface Repository<T, TId> {
214
- findById(id: TId): Promise<T | null>;
215
- findMany(filter?: Partial<T>): Promise<T[]>;
216
- create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>): Promise<T>;
217
- update(id: TId, data: Partial<Omit<T, 'id'>>): Promise<T>;
218
- delete(id: TId): Promise<void>;
219
- }
220
-
221
- class UserRepository implements Repository<User, UserId> {
222
- async findById(id: UserId) { /* ... */ }
223
- // TypeScript enforces all interface methods are implemented
224
- }
225
- ```
226
-
227
- ---
228
-
229
- ### Common Pitfalls to Avoid
230
-
231
- | Anti-Pattern | Problem | Solution |
232
- |---|---|---|
233
- | `as any` | Disables type checking | Use `unknown` + narrowing or Zod |
234
- | `as Type` (unsafe cast) | Bypasses structural checking | Use type guards or `satisfies` |
235
- | `// @ts-ignore` | Silences real errors | Fix the root type issue |
236
- | `!` non-null assertion | Runtime errors if null | Use optional chaining + nullish coalescing |
237
- | `Object` / `{}` type | Accepts anything non-null | Use specific types or `Record<string, unknown>` |
238
- | Implicit `any` in callbacks | Breaks type inference | Always type function parameters |
239
-
240
- ---
241
-
242
- ### The `satisfies` Operator (TS 4.9+)
243
- ```typescript
244
- // Validates against a type without widening the inferred type
245
- const config = {
246
- port: 3000,
247
- host: 'localhost',
248
- debug: true,
249
- } satisfies Record<string, string | number | boolean>;
250
-
251
- // config.port is still inferred as `3000` (literal), not `number`
252
- config.port.toFixed(2); // Works! Literal type preserved.
253
- ```
254
-
255
- ---
256
-
257
- <a name="bahasa-indonesia"></a>
258
- ## Bahasa Indonesia
259
-
260
- ### Deskripsi
261
- Panduan TypeScript level ahli mencakup sistem tipe tingkat lanjut, penerapan strict mode, pemrograman generik, utility types, branded types, dan pola type-safe untuk aplikasi produksi. Menargetkan fitur **TypeScript 5.4+** termasuk `NoInfer`, deklarasi `using`, peningkatan variadic tuple, dan parameter tipe `const`.
262
-
263
- ### Kondisi Pemicu
264
- - Menulis TypeScript dengan generic constraints tingkat lanjut.
265
- - Menerapkan type safety ketat di codebase yang ada.
266
- - Merancang kontrak API type-safe (REST, tRPC, Zod schema).
267
- - Mengimplementasikan branded types untuk pemodelan domain.
268
- - Menyelesaikan type error kompleks atau polusi `any`.
269
- - Menyiapkan `tsconfig.json` untuk proyek strict.
270
- - Menulis utility types atau type helpers TypeScript.
271
-
272
- ### Panduan Singkat
273
-
274
- - **Aktifkan strict mode**: Selalu gunakan `"strict": true` ditambah `noUncheckedIndexedAccess` dan `exactOptionalPropertyTypes`.
275
- - **Branded Types**: Cegah pencampuran primitif yang berbeda secara semantis (UserId vs PostId).
276
- - **Discriminated Union**: Gunakan untuk state machine dan variant data yang terbatas.
277
- - **Zod**: Validasi data eksternal dan turunkan tipe TypeScript dari schema Zod.
278
- - **Hindari `as any`**: Gunakan `unknown` dengan narrowing atau Zod untuk data yang tidak diketahui tipenya.
279
- - **`satisfies` operator**: Validasi objek terhadap tipe tanpa melebarkan tipe yang diinferensi.
5
+ ---
6
+
7
+ # TypeScript Expert (TypeScript 5.8+ Edition)
8
+
9
+ [English](#english) | [Bahasa Indonesia](#bahasa-indonesia)
10
+
11
+ ---
12
+
13
+ <a name="english"></a>
14
+ ## English
15
+
16
+ ### Orchestration & Integration
17
+ Connects and orchestrates with relevant domain skills like `brainstorming`, `zero-to-prod-orchestrator`, and `project-context-mapper` to ensure cohesive execution.
18
+
19
+ ### Description
20
+ Expert-level TypeScript development covering the advanced type system, strict mode enforcement, generic programming, utility types, branded types, and type-safe patterns for production applications. Targets **TypeScript 5.8+** features including inferred type predicates, isolated declarations, `NoInfer`, `using` declarations, variadic tuple improvements, and `const` type parameters.
21
+
22
+ ### Trigger Conditions
23
+ - Writing TypeScript with advanced generic constraints.
24
+ - Enforcing strict type safety in existing codebases.
25
+ - Designing type-safe API contracts (REST, tRPC, Zod schemas).
26
+ - Implementing branded types for domain modeling.
27
+ - Resolving complex type errors or `any` pollution.
28
+ - Setting up `tsconfig.json` for strict projects.
29
+ - Writing TypeScript utility types or type helpers.
30
+
31
+ ---
32
+
33
+ ### TypeScript 5.x — Key Features
34
+
35
+ #### `using` Declarations (Explicit Resource Management, TS 5.2)
36
+ ```typescript
37
+ // Automatically calls [Symbol.dispose] on scope exit
38
+ function processFile(path: string) {
39
+ using handle = openFile(path); // disposed when function exits
40
+ handle.write('data');
41
+ }
42
+
43
+ // Async version with [Symbol.asyncDispose]
44
+ async function processDatabase() {
45
+ await using conn = await getConnection();
46
+ await conn.query('SELECT 1');
47
+ } // conn.close() called automatically
48
+ ```
49
+
50
+ #### `NoInfer<T>` Utility Type (TS 5.4)
51
+ ```typescript
52
+ // Prevents unintended type widening in generic inference
53
+ function createState<T>(initial: T, fallback: NoInfer<T>): T {
54
+ return initial ?? fallback;
55
+ }
56
+
57
+ // TS now errors if fallback type doesn't match initial
58
+ createState('hello', 42); // Error: Argument of type 'number' is not assignable to type 'string'
59
+ ```
60
+
61
+ #### `const` Type Parameters (TS 5.0)
62
+ ```typescript
63
+ // Infer literal types from generic arguments
64
+ function identity<const T>(value: T): T { return value; }
65
+
66
+ const a = identity(['a', 'b', 'c']); // type: readonly ["a", "b", "c"]
67
+ const b = identity({ x: 10 }); // type: { readonly x: 10 }
68
+ ```
69
+
70
+ ---
71
+
72
+ ### TypeScript 5.5 - 5.8 New Features
73
+
74
+ #### Inferred Type Predicates (TS 5.5)
75
+ ```typescript
76
+ // TypeScript now infers type predicates from return statements automatically
77
+ const nums = [1, null, 2, undefined, 3].filter((x) => x !== null);
78
+ // nums is now inferred as number[] — no manual type assertion needed!
79
+
80
+ // Before TS 5.5 you needed:
81
+ const nums = [1, null, 2].filter((x): x is number => x !== null);
82
+
83
+ // Works with any refinement pattern:
84
+ function isString(x: unknown) {
85
+ return typeof x === 'string'; // TS 5.5 infers: (x: unknown) => x is string
86
+ }
87
+ ```
88
+
89
+ #### Isolated Declarations (TS 5.5)
90
+ ```typescript
91
+ // New tsconfig option: "isolatedDeclarations": true
92
+ // Forces explicit return types on all exported functions — enables
93
+ // parallel .d.ts generation (massively speeds up monorepo builds)
94
+ export function add(a: number, b: number): number { // explicit return type required
95
+ return a + b;
96
+ }
97
+ ```
98
+
99
+ #### Iterator Helper Methods (TS 5.6 — ES2025)
100
+ ```typescript
101
+ // Native iterator methods now fully typed
102
+ const result = [1, 2, 3, 4, 5]
103
+ .values() // IteratorObject
104
+ .filter(x => x % 2 === 0) // 2, 4
105
+ .map(x => x * 10) // 20, 40
106
+ .toArray(); // [20, 40]
107
+ ```
108
+
109
+ ---
110
+
111
+ ### Strict Mode Configuration
112
+
113
+ ```json
114
+ // tsconfig.json recommended strict config for Next.js / monorepo projects
115
+ {
116
+ "compilerOptions": {
117
+ "target": "ES2022",
118
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
119
+ "module": "Preserve",
120
+ "moduleResolution": "Bundler",
121
+ "strict": true,
122
+ "noUncheckedIndexedAccess": true,
123
+ "exactOptionalPropertyTypes": true,
124
+ "noImplicitReturns": true,
125
+ "noFallthroughCasesInSwitch": true,
126
+ "noImplicitOverride": true,
127
+ "isolatedModules": true,
128
+ "isolatedDeclarations": true,
129
+ "verbatimModuleSyntax": true,
130
+ "forceConsistentCasingInFileNames": true,
131
+ "skipLibCheck": true
132
+ }
133
+ }
134
+ ```
135
+
136
+ > **Note**: Use `"moduleResolution": "Bundler"` with `"module": "Preserve"` for Vite, Next.js, and other bundler-based projects. Use `"NodeNext"` for Node.js/Bun/Deno runtimes.
137
+
138
+ ---
139
+
140
+ ### Advanced Type Patterns
141
+
142
+ #### Branded Types for Domain Modeling
143
+ ```typescript
144
+ // Prevent mixing semantically different primitives
145
+ type Brand<T, B extends string> = T & { readonly __brand: B };
146
+
147
+ type UserId = Brand<string, 'UserId'>;
148
+ type PostId = Brand<string, 'PostId'>;
149
+ type Email = Brand<string, 'Email'>;
150
+
151
+ // Constructor functions with validation
152
+ function createUserId(id: string): UserId {
153
+ if (!id.startsWith('user_')) throw new Error('Invalid user ID format');
154
+ return id as UserId;
155
+ }
156
+
157
+ function getUser(id: UserId): Promise<User> { /* ... */ }
158
+
159
+ const postId = 'post_abc' as PostId;
160
+ getUser(postId); // Compile error: PostId is not assignable to UserId
161
+ ```
162
+
163
+ #### Discriminated Unions for State Machines
164
+ ```typescript
165
+ type ApiState<T> =
166
+ | { status: 'idle' }
167
+ | { status: 'loading' }
168
+ | { status: 'success'; data: T }
169
+ | { status: 'error'; error: Error };
170
+
171
+ function render<T>(state: ApiState<T>) {
172
+ switch (state.status) {
173
+ case 'idle': return 'Idle';
174
+ case 'loading': return 'Loading...';
175
+ case 'success': return `Data: ${JSON.stringify(state.data)}`;
176
+ case 'error': return `Error: ${state.error.message}`;
177
+ // TypeScript enforces exhaustive matching
178
+ }
179
+ }
180
+ ```
181
+
182
+ #### Template Literal Types
183
+ ```typescript
184
+ type EventName = 'click' | 'focus' | 'blur';
185
+ type HandlerName = `on${Capitalize<EventName>}`;
186
+ // Result: 'onClick' | 'onFocus' | 'onBlur'
187
+
188
+ type DeepReadonly<T> = {
189
+ readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
190
+ };
191
+
192
+ type Paths<T, Prefix extends string = ''> = {
193
+ [K in keyof T & string]: T[K] extends object
194
+ ? Paths<T[K], `${Prefix}${K}.`>
195
+ : `${Prefix}${K}`;
196
+ }[keyof T & string];
197
+
198
+ // Paths<{ user: { name: string; age: number } }> = "user.name" | "user.age"
199
+ ```
200
+
201
+ #### Conditional Types and `infer`
202
+ ```typescript
203
+ type UnwrapPromise<T> = T extends Promise<infer U> ? U : T;
204
+ type ArrayElement<T> = T extends (infer U)[] ? U : never;
205
+ type ReturnType<T> = T extends (...args: any[]) => infer R ? R : never;
206
+
207
+ // Extract function parameter types
208
+ type Parameters<T extends (...args: any) => any> =
209
+ T extends (...args: infer P) => any ? P : never;
210
+ ```
211
+
212
+ ---
213
+
214
+ ### Type-Safe Patterns
215
+
216
+ #### Zod Schema + TypeScript Integration
217
+ ```typescript
218
+ import { z } from 'zod';
219
+
220
+ const UserSchema = z.object({
221
+ id: z.string().cuid(),
222
+ email: z.string().email(),
223
+ role: z.enum(['USER', 'ADMIN']),
224
+ createdAt: z.coerce.date(),
225
+ });
226
+
227
+ type User = z.infer<typeof UserSchema>; // Derive type from schema
228
+
229
+ // Type-safe parsing with error handling
230
+ function parseUser(data: unknown): User {
231
+ return UserSchema.parse(data); // throws ZodError on failure
232
+ }
233
+
234
+ const safeResult = UserSchema.safeParse(data);
235
+ if (safeResult.success) {
236
+ console.log(safeResult.data.email); // fully typed
237
+ }
238
+ ```
239
+
240
+ #### Type-Safe Environment Variables
241
+ ```typescript
242
+ // env.ts validate env at startup
243
+ import { z } from 'zod';
244
+
245
+ const envSchema = z.object({
246
+ DATABASE_URL: z.string().url(),
247
+ NEXTAUTH_SECRET: z.string().min(32),
248
+ NODE_ENV: z.enum(['development', 'test', 'production']),
249
+ PORT: z.coerce.number().default(3000),
250
+ });
251
+
252
+ export const env = envSchema.parse(process.env);
253
+ // env.PORT is now type `number`, not `string | undefined`
254
+ ```
255
+
256
+ #### Generic Repository Pattern
257
+ ```typescript
258
+ interface Repository<T, TId> {
259
+ findById(id: TId): Promise<T | null>;
260
+ findMany(filter?: Partial<T>): Promise<T[]>;
261
+ create(data: Omit<T, 'id' | 'createdAt' | 'updatedAt'>): Promise<T>;
262
+ update(id: TId, data: Partial<Omit<T, 'id'>>): Promise<T>;
263
+ delete(id: TId): Promise<void>;
264
+ }
265
+
266
+ class UserRepository implements Repository<User, UserId> {
267
+ async findById(id: UserId) { /* ... */ }
268
+ // TypeScript enforces all interface methods are implemented
269
+ }
270
+ ```
271
+
272
+ ---
273
+
274
+ ### Common Pitfalls to Avoid
275
+
276
+ | Anti-Pattern | Problem | Solution |
277
+ |---|---|---|
278
+ | `as any` | Disables type checking | Use `unknown` + narrowing or Zod |
279
+ | `as Type` (unsafe cast) | Bypasses structural checking | Use type guards or `satisfies` |
280
+ | `// @ts-ignore` | Silences real errors | Fix the root type issue |
281
+ | `!` non-null assertion | Runtime errors if null | Use optional chaining + nullish coalescing |
282
+ | `Object` / `{}` type | Accepts anything non-null | Use specific types or `Record<string, unknown>` |
283
+ | Implicit `any` in callbacks | Breaks type inference | Always type function parameters |
284
+
285
+ ---
286
+
287
+ ### The `satisfies` Operator (TS 4.9+)
288
+ ```typescript
289
+ // Validates against a type without widening the inferred type
290
+ const config = {
291
+ port: 3000,
292
+ host: 'localhost',
293
+ debug: true,
294
+ } satisfies Record<string, string | number | boolean>;
295
+
296
+ // config.port is still inferred as `3000` (literal), not `number`
297
+ config.port.toFixed(2); // Works! Literal type preserved.
298
+ ```
299
+
300
+ ---
301
+
302
+ <a name="bahasa-indonesia"></a>
303
+ ## Bahasa Indonesia
304
+
305
+ ### Integrasi Orkestrasi
306
+ Terhubung dan mengorkestrasi skill domain yang relevan seperti `brainstorming`, `zero-to-prod-orchestrator`, dan `project-context-mapper` untuk memastikan eksekusi yang kohesif.
307
+
308
+ ### Deskripsi
309
+ Panduan TypeScript level ahli mencakup sistem tipe tingkat lanjut, penerapan strict mode, pemrograman generik, utility types, branded types, dan pola type-safe untuk aplikasi produksi. Menargetkan fitur **TypeScript 5.8+** termasuk inferred type predicates, isolated declarations, `NoInfer`, deklarasi `using`, peningkatan variadic tuple, dan parameter tipe `const`.
310
+
311
+ ### Kondisi Pemicu
312
+ - Menulis TypeScript dengan generic constraints tingkat lanjut.
313
+ - Menerapkan type safety ketat di codebase yang ada.
314
+ - Merancang kontrak API type-safe (REST, tRPC, Zod schema).
315
+ - Mengimplementasikan branded types untuk pemodelan domain.
316
+ - Menyelesaikan type error kompleks atau polusi `any`.
317
+ - Menyiapkan `tsconfig.json` untuk proyek strict dengan `isolatedDeclarations`.
318
+ - Menulis utility types atau type helpers TypeScript.
319
+
320
+ ### Panduan Singkat
321
+
322
+ - **Aktifkan strict mode**: Selalu gunakan `"strict": true` ditambah `noUncheckedIndexedAccess`, `exactOptionalPropertyTypes`, dan `isolatedDeclarations`.
323
+ - **Inferred Type Predicates** (TS 5.5): Filter array tanpa type assertion manual — TypeScript inferensikan sendiri.
324
+ - **Isolated Declarations** (TS 5.5): Aktifkan untuk mempercepat build monorepo via parallel `.d.ts` generation.
325
+ - **Branded Types**: Cegah pencampuran primitif yang berbeda secara semantis (UserId vs PostId).
326
+ - **Discriminated Union**: Gunakan untuk state machine dan variant data yang terbatas.
327
+ - **Zod**: Validasi data eksternal dan turunkan tipe TypeScript dari schema Zod.
328
+ - **Hindari `as any`**: Gunakan `unknown` dengan narrowing atau Zod untuk data yang tidak diketahui tipenya.
329
+ - **`satisfies` operator**: Validasi objek terhadap tipe tanpa melebarkan tipe yang diinferensi.
330
+ - **`moduleResolution: Bundler`**: Gunakan untuk proyek Next.js/Vite; `NodeNext` untuk Node.js/Bun backend.