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