omgkit 2.0.7 → 2.1.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 (27) hide show
  1. package/package.json +2 -2
  2. package/plugin/skills/backend/api-architecture/SKILL.md +857 -0
  3. package/plugin/skills/backend/caching-strategies/SKILL.md +755 -0
  4. package/plugin/skills/backend/event-driven-architecture/SKILL.md +753 -0
  5. package/plugin/skills/backend/real-time-systems/SKILL.md +635 -0
  6. package/plugin/skills/databases/database-optimization/SKILL.md +571 -0
  7. package/plugin/skills/databases/postgresql/SKILL.md +494 -18
  8. package/plugin/skills/devops/docker/SKILL.md +466 -18
  9. package/plugin/skills/devops/monorepo-management/SKILL.md +595 -0
  10. package/plugin/skills/devops/observability/SKILL.md +622 -0
  11. package/plugin/skills/devops/performance-profiling/SKILL.md +905 -0
  12. package/plugin/skills/frameworks/nextjs/SKILL.md +407 -44
  13. package/plugin/skills/frameworks/react/SKILL.md +1006 -32
  14. package/plugin/skills/frontend/advanced-ui-design/SKILL.md +426 -0
  15. package/plugin/skills/integrations/ai-integration/SKILL.md +730 -0
  16. package/plugin/skills/integrations/payment-integration/SKILL.md +735 -0
  17. package/plugin/skills/languages/python/SKILL.md +489 -25
  18. package/plugin/skills/languages/typescript/SKILL.md +379 -30
  19. package/plugin/skills/methodology/problem-solving/SKILL.md +355 -0
  20. package/plugin/skills/methodology/research-validation/SKILL.md +668 -0
  21. package/plugin/skills/methodology/sequential-thinking/SKILL.md +260 -0
  22. package/plugin/skills/mobile/mobile-development/SKILL.md +756 -0
  23. package/plugin/skills/security/security-hardening/SKILL.md +633 -0
  24. package/plugin/skills/tools/document-processing/SKILL.md +916 -0
  25. package/plugin/skills/tools/image-processing/SKILL.md +748 -0
  26. package/plugin/skills/tools/mcp-development/SKILL.md +883 -0
  27. package/plugin/skills/tools/media-processing/SKILL.md +831 -0
@@ -1,66 +1,415 @@
1
1
  ---
2
2
  name: typescript
3
- description: TypeScript development. Use when writing TypeScript, using strict types, or type-safe code.
3
+ description: TypeScript development with advanced type safety, generics, utility types, and best practices
4
+ category: languages
5
+ triggers:
6
+ - typescript
7
+ - ts
8
+ - type
9
+ - interface
10
+ - generic
11
+ - type safety
4
12
  ---
5
13
 
6
- # TypeScript Skill
14
+ # TypeScript
7
15
 
8
- ## Patterns
16
+ Enterprise-grade **TypeScript development** following industry best practices. This skill covers type system mastery, advanced patterns, generic programming, utility types, and type-safe design patterns used by top engineering teams.
17
+
18
+ ## Purpose
19
+
20
+ Write type-safe code that scales with confidence:
21
+
22
+ - Master TypeScript's type system
23
+ - Leverage generics for reusable code
24
+ - Use utility types effectively
25
+ - Implement type-safe patterns
26
+ - Handle complex type scenarios
27
+ - Improve code maintainability
28
+
29
+ ## Features
30
+
31
+ ### 1. Type Fundamentals
9
32
 
10
- ### Strict Types
11
33
  ```typescript
34
+ // Primitive types
35
+ const name: string = 'John';
36
+ const age: number = 30;
37
+ const isActive: boolean = true;
38
+
39
+ // Arrays and tuples
40
+ const numbers: number[] = [1, 2, 3];
41
+ const tuple: [string, number, boolean] = ['John', 30, true];
42
+ const namedTuple: [name: string, age: number] = ['John', 30];
43
+
44
+ // Object types
12
45
  interface User {
13
46
  id: string;
47
+ name: string;
14
48
  email: string;
15
- createdAt: Date;
49
+ age?: number; // Optional
50
+ readonly createdAt: Date; // Readonly
51
+ }
52
+
53
+ // Type aliases
54
+ type ID = string | number;
55
+ type Status = 'pending' | 'active' | 'inactive';
56
+ type Callback = (error: Error | null, result?: unknown) => void;
57
+
58
+ // Union and intersection types
59
+ type StringOrNumber = string | number;
60
+ type AdminUser = User & { role: 'admin'; permissions: string[] };
61
+
62
+ // Literal types
63
+ type Direction = 'north' | 'south' | 'east' | 'west';
64
+ type HTTPMethod = 'GET' | 'POST' | 'PUT' | 'DELETE';
65
+
66
+ // Template literal types
67
+ type EventName = `on${Capitalize<string>}`;
68
+ type APIRoute = `/api/${string}`;
69
+ ```
70
+
71
+ ### 2. Advanced Type Patterns
72
+
73
+ ```typescript
74
+ // Discriminated unions
75
+ type Result<T, E = Error> =
76
+ | { success: true; data: T }
77
+ | { success: false; error: E };
78
+
79
+ function processResult<T>(result: Result<T>): T | null {
80
+ if (result.success) {
81
+ return result.data;
82
+ } else {
83
+ console.error(result.error);
84
+ return null;
85
+ }
86
+ }
87
+
88
+ // Type guards
89
+ function isString(value: unknown): value is string {
90
+ return typeof value === 'string';
16
91
  }
17
92
 
18
- interface CreateUserInput {
93
+ function isUser(value: unknown): value is User {
94
+ return (
95
+ typeof value === 'object' &&
96
+ value !== null &&
97
+ 'id' in value &&
98
+ 'email' in value
99
+ );
100
+ }
101
+
102
+ // Assertion functions
103
+ function assertDefined<T>(value: T | null | undefined): asserts value is T {
104
+ if (value === null || value === undefined) {
105
+ throw new Error('Value is not defined');
106
+ }
107
+ }
108
+
109
+ // Conditional types
110
+ type NonNullable<T> = T extends null | undefined ? never : T;
111
+ type ExtractArray<T> = T extends (infer U)[] ? U : never;
112
+ type ReturnTypeOf<T> = T extends (...args: any[]) => infer R ? R : never;
113
+
114
+ // Mapped types
115
+ type Nullable<T> = { [K in keyof T]: T[K] | null };
116
+ type Optional<T> = { [K in keyof T]?: T[K] };
117
+ type Readonly<T> = { readonly [K in keyof T]: T[K] };
118
+ ```
119
+
120
+ ### 3. Generics
121
+
122
+ ```typescript
123
+ // Generic functions
124
+ function identity<T>(value: T): T {
125
+ return value;
126
+ }
127
+
128
+ function first<T>(array: T[]): T | undefined {
129
+ return array[0];
130
+ }
131
+
132
+ function map<T, U>(array: T[], fn: (item: T) => U): U[] {
133
+ return array.map(fn);
134
+ }
135
+
136
+ // Generic constraints
137
+ interface Lengthwise {
138
+ length: number;
139
+ }
140
+
141
+ function logLength<T extends Lengthwise>(value: T): T {
142
+ console.log(value.length);
143
+ return value;
144
+ }
145
+
146
+ // Generic interfaces
147
+ interface Repository<T, ID = string> {
148
+ findById(id: ID): Promise<T | null>;
149
+ findAll(): Promise<T[]>;
150
+ create(data: Omit<T, 'id'>): Promise<T>;
151
+ update(id: ID, data: Partial<T>): Promise<T | null>;
152
+ delete(id: ID): Promise<boolean>;
153
+ }
154
+
155
+ // Generic classes
156
+ class Stack<T> {
157
+ private items: T[] = [];
158
+
159
+ push(item: T): void {
160
+ this.items.push(item);
161
+ }
162
+
163
+ pop(): T | undefined {
164
+ return this.items.pop();
165
+ }
166
+
167
+ peek(): T | undefined {
168
+ return this.items[this.items.length - 1];
169
+ }
170
+ }
171
+
172
+ // Constrained generic with keyof
173
+ function getProperty<T, K extends keyof T>(obj: T, key: K): T[K] {
174
+ return obj[key];
175
+ }
176
+ ```
177
+
178
+ ### 4. Utility Types
179
+
180
+ ```typescript
181
+ interface User {
182
+ id: string;
183
+ name: string;
19
184
  email: string;
20
185
  password: string;
186
+ role: 'user' | 'admin';
187
+ createdAt: Date;
188
+ }
189
+
190
+ // Partial - make all optional
191
+ type UserUpdate = Partial<User>;
192
+
193
+ // Required - make all required
194
+ type CompleteUser = Required<User>;
195
+
196
+ // Readonly - make all readonly
197
+ type ImmutableUser = Readonly<User>;
198
+
199
+ // Pick - select specific properties
200
+ type UserCredentials = Pick<User, 'email' | 'password'>;
201
+
202
+ // Omit - exclude specific properties
203
+ type PublicUser = Omit<User, 'password'>;
204
+
205
+ // Record - create object type
206
+ type UserRoles = Record<string, User['role']>;
207
+
208
+ // Exclude/Extract - work with unions
209
+ type NonAdminRole = Exclude<User['role'], 'admin'>;
210
+
211
+ // Parameters/ReturnType - function types
212
+ type FunctionParams = Parameters<(a: string, b: number) => void>;
213
+ type FunctionReturn = ReturnType<() => Promise<User>>;
214
+
215
+ // Custom utility types
216
+ type DeepPartial<T> = {
217
+ [K in keyof T]?: T[K] extends object ? DeepPartial<T[K]> : T[K];
218
+ };
219
+
220
+ type DeepReadonly<T> = {
221
+ readonly [K in keyof T]: T[K] extends object ? DeepReadonly<T[K]> : T[K];
222
+ };
223
+ ```
224
+
225
+ ### 5. Type-Safe API Design
226
+
227
+ ```typescript
228
+ // Type-safe API client
229
+ interface APIEndpoints {
230
+ '/users': {
231
+ GET: { response: User[]; params: { page?: number } };
232
+ POST: { response: User; body: Omit<User, 'id'> };
233
+ };
234
+ '/users/:id': {
235
+ GET: { response: User; params: { id: string } };
236
+ DELETE: { response: void; params: { id: string } };
237
+ };
21
238
  }
22
239
 
23
- function createUser(input: CreateUserInput): Promise<User> {
24
- ...
240
+ async function apiRequest<
241
+ Path extends keyof APIEndpoints,
242
+ Method extends keyof APIEndpoints[Path]
243
+ >(
244
+ path: Path,
245
+ method: Method,
246
+ config?: APIEndpoints[Path][Method]
247
+ ): Promise<APIEndpoints[Path][Method]['response']> {
248
+ const response = await fetch(path, { method: method as string });
249
+ return response.json();
25
250
  }
26
251
  ```
27
252
 
28
- ### Generics
253
+ ### 6. Error Handling Patterns
254
+
29
255
  ```typescript
256
+ // Type-safe Result type
30
257
  type Result<T, E = Error> =
31
- | { ok: true; data: T }
258
+ | { ok: true; value: T }
32
259
  | { ok: false; error: E };
33
260
 
34
- async function fetchUser(id: string): Promise<Result<User>> {
261
+ function ok<T>(value: T): Result<T, never> {
262
+ return { ok: true, value };
263
+ }
264
+
265
+ function err<E>(error: E): Result<never, E> {
266
+ return { ok: false, error };
267
+ }
268
+
269
+ // Error class hierarchy
270
+ class AppError extends Error {
271
+ constructor(
272
+ message: string,
273
+ public readonly code: string,
274
+ public readonly statusCode: number = 500
275
+ ) {
276
+ super(message);
277
+ this.name = 'AppError';
278
+ }
279
+ }
280
+
281
+ class NotFoundError extends AppError {
282
+ constructor(resource: string, id: string) {
283
+ super(`${resource} with id ${id} not found`, 'NOT_FOUND', 404);
284
+ }
285
+ }
286
+
287
+ // Try/catch wrapper
288
+ async function tryCatch<T>(fn: () => Promise<T>): Promise<Result<T, Error>> {
35
289
  try {
36
- const user = await db.users.findById(id);
37
- return { ok: true, data: user };
290
+ const value = await fn();
291
+ return ok(value);
38
292
  } catch (error) {
39
- return { ok: false, error };
293
+ return err(error instanceof Error ? error : new Error(String(error)));
40
294
  }
41
295
  }
42
296
  ```
43
297
 
44
- ### Utility Types
298
+ ### 7. Declaration Files
299
+
45
300
  ```typescript
46
- type Partial<T> = { [P in keyof T]?: T[P] };
47
- type Required<T> = { [P in keyof T]-?: T[P] };
48
- type Pick<T, K extends keyof T> = { [P in K]: T[P] };
49
- type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
301
+ // types/express.d.ts
302
+ declare global {
303
+ namespace Express {
304
+ interface Request {
305
+ user?: User;
306
+ requestId: string;
307
+ }
308
+ }
309
+ }
310
+
311
+ // types/environment.d.ts
312
+ declare global {
313
+ namespace NodeJS {
314
+ interface ProcessEnv {
315
+ NODE_ENV: 'development' | 'production' | 'test';
316
+ DATABASE_URL: string;
317
+ API_KEY: string;
318
+ }
319
+ }
320
+ }
321
+
322
+ // Module declarations
323
+ declare module '*.svg' {
324
+ const content: React.FunctionComponent<React.SVGAttributes<SVGElement>>;
325
+ export default content;
326
+ }
50
327
  ```
51
328
 
52
- ### Const Assertions
329
+ ## Use Cases
330
+
331
+ ### Type-Safe Redux State
53
332
  ```typescript
54
- const CONFIG = {
55
- API_URL: 'https://api.example.com',
56
- TIMEOUT: 5000,
57
- } as const;
333
+ interface AppState {
334
+ users: UsersState;
335
+ products: ProductsState;
336
+ }
337
+
338
+ type Action =
339
+ | { type: 'USERS_LOADED'; payload: User[] }
340
+ | { type: 'USER_ADDED'; payload: User };
341
+
342
+ function reducer(state: AppState, action: Action): AppState {
343
+ switch (action.type) {
344
+ case 'USERS_LOADED':
345
+ return { ...state, users: { items: action.payload } };
346
+ default:
347
+ return state;
348
+ }
349
+ }
350
+ ```
351
+
352
+ ### Type-Safe Event Emitter
353
+ ```typescript
354
+ type EventMap = {
355
+ userCreated: { user: User };
356
+ userDeleted: { userId: string };
357
+ };
358
+
359
+ class TypedEventEmitter<Events extends Record<string, unknown>> {
360
+ private listeners = new Map<keyof Events, Set<(data: any) => void>>();
361
+
362
+ on<E extends keyof Events>(event: E, listener: (data: Events[E]) => void): void {
363
+ if (!this.listeners.has(event)) {
364
+ this.listeners.set(event, new Set());
365
+ }
366
+ this.listeners.get(event)!.add(listener);
367
+ }
368
+
369
+ emit<E extends keyof Events>(event: E, data: Events[E]): void {
370
+ this.listeners.get(event)?.forEach(listener => listener(data));
371
+ }
372
+ }
58
373
  ```
59
374
 
60
375
  ## Best Practices
61
- - Enable strict mode
62
- - Use interfaces for objects
63
- - Use type for unions/intersections
64
- - Avoid `any`
65
- - Use const assertions
66
- - Prefer unknown over any
376
+
377
+ ### Do's
378
+ - Enable strict mode in tsconfig
379
+ - Use interfaces for object shapes
380
+ - Leverage type inference
381
+ - Use discriminated unions for state
382
+ - Prefer readonly for immutable data
383
+ - Use unknown over any
384
+ - Create reusable generic types
385
+
386
+ ### Don'ts
387
+ - Don't use any unless necessary
388
+ - Don't ignore errors with @ts-ignore
389
+ - Don't overuse type assertions
390
+ - Don't create overly complex generics
391
+ - Don't forget null/undefined handling
392
+ - Don't skip strict null checks
393
+
394
+ ## Configuration
395
+
396
+ ```json
397
+ {
398
+ "compilerOptions": {
399
+ "target": "ES2022",
400
+ "module": "ESNext",
401
+ "strict": true,
402
+ "noImplicitAny": true,
403
+ "strictNullChecks": true,
404
+ "noUnusedLocals": true,
405
+ "esModuleInterop": true,
406
+ "skipLibCheck": true
407
+ }
408
+ }
409
+ ```
410
+
411
+ ## References
412
+
413
+ - [TypeScript Documentation](https://www.typescriptlang.org/docs)
414
+ - [TypeScript Deep Dive](https://basarat.gitbook.io/typescript)
415
+ - [Type Challenges](https://github.com/type-challenges/type-challenges)