omgkit 2.1.0 → 2.2.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.
- package/package.json +1 -1
- package/plugin/skills/SKILL_STANDARDS.md +743 -0
- package/plugin/skills/databases/mongodb/SKILL.md +797 -28
- package/plugin/skills/databases/postgresql/SKILL.md +494 -18
- package/plugin/skills/databases/prisma/SKILL.md +776 -30
- package/plugin/skills/databases/redis/SKILL.md +885 -25
- package/plugin/skills/devops/aws/SKILL.md +686 -28
- package/plugin/skills/devops/docker/SKILL.md +466 -18
- package/plugin/skills/devops/github-actions/SKILL.md +684 -29
- package/plugin/skills/devops/kubernetes/SKILL.md +621 -24
- package/plugin/skills/frameworks/django/SKILL.md +920 -20
- package/plugin/skills/frameworks/express/SKILL.md +1361 -35
- package/plugin/skills/frameworks/fastapi/SKILL.md +1260 -33
- package/plugin/skills/frameworks/laravel/SKILL.md +1244 -31
- package/plugin/skills/frameworks/nestjs/SKILL.md +1005 -26
- package/plugin/skills/frameworks/nextjs/SKILL.md +407 -44
- package/plugin/skills/frameworks/rails/SKILL.md +594 -28
- package/plugin/skills/frameworks/react/SKILL.md +1006 -32
- package/plugin/skills/frameworks/spring/SKILL.md +528 -35
- package/plugin/skills/frameworks/vue/SKILL.md +1296 -27
- package/plugin/skills/frontend/accessibility/SKILL.md +1108 -34
- package/plugin/skills/frontend/frontend-design/SKILL.md +1304 -26
- package/plugin/skills/frontend/responsive/SKILL.md +847 -21
- package/plugin/skills/frontend/shadcn-ui/SKILL.md +976 -38
- package/plugin/skills/frontend/tailwindcss/SKILL.md +831 -35
- package/plugin/skills/frontend/threejs/SKILL.md +1298 -29
- package/plugin/skills/languages/javascript/SKILL.md +935 -31
- package/plugin/skills/languages/python/SKILL.md +489 -25
- package/plugin/skills/languages/typescript/SKILL.md +379 -30
- package/plugin/skills/methodology/brainstorming/SKILL.md +597 -23
- package/plugin/skills/methodology/defense-in-depth/SKILL.md +832 -34
- package/plugin/skills/methodology/dispatching-parallel-agents/SKILL.md +665 -31
- package/plugin/skills/methodology/executing-plans/SKILL.md +556 -24
- package/plugin/skills/methodology/finishing-development-branch/SKILL.md +595 -25
- package/plugin/skills/methodology/problem-solving/SKILL.md +429 -61
- package/plugin/skills/methodology/receiving-code-review/SKILL.md +536 -24
- package/plugin/skills/methodology/requesting-code-review/SKILL.md +632 -21
- package/plugin/skills/methodology/root-cause-tracing/SKILL.md +641 -30
- package/plugin/skills/methodology/sequential-thinking/SKILL.md +262 -3
- package/plugin/skills/methodology/systematic-debugging/SKILL.md +571 -32
- package/plugin/skills/methodology/test-driven-development/SKILL.md +779 -24
- package/plugin/skills/methodology/testing-anti-patterns/SKILL.md +691 -29
- package/plugin/skills/methodology/token-optimization/SKILL.md +598 -29
- package/plugin/skills/methodology/verification-before-completion/SKILL.md +543 -22
- package/plugin/skills/methodology/writing-plans/SKILL.md +590 -18
- package/plugin/skills/omega/omega-architecture/SKILL.md +838 -39
- package/plugin/skills/omega/omega-coding/SKILL.md +636 -39
- package/plugin/skills/omega/omega-sprint/SKILL.md +855 -48
- package/plugin/skills/omega/omega-testing/SKILL.md +940 -41
- package/plugin/skills/omega/omega-thinking/SKILL.md +703 -50
- package/plugin/skills/security/better-auth/SKILL.md +1065 -28
- package/plugin/skills/security/oauth/SKILL.md +968 -31
- package/plugin/skills/security/owasp/SKILL.md +894 -33
- package/plugin/skills/testing/playwright/SKILL.md +764 -38
- package/plugin/skills/testing/pytest/SKILL.md +873 -36
- package/plugin/skills/testing/vitest/SKILL.md +980 -35
|
@@ -1,66 +1,415 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: typescript
|
|
3
|
-
description: TypeScript development
|
|
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
|
|
14
|
+
# TypeScript
|
|
7
15
|
|
|
8
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
###
|
|
253
|
+
### 6. Error Handling Patterns
|
|
254
|
+
|
|
29
255
|
```typescript
|
|
256
|
+
// Type-safe Result type
|
|
30
257
|
type Result<T, E = Error> =
|
|
31
|
-
| { ok: true;
|
|
258
|
+
| { ok: true; value: T }
|
|
32
259
|
| { ok: false; error: E };
|
|
33
260
|
|
|
34
|
-
|
|
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
|
|
37
|
-
return
|
|
290
|
+
const value = await fn();
|
|
291
|
+
return ok(value);
|
|
38
292
|
} catch (error) {
|
|
39
|
-
return
|
|
293
|
+
return err(error instanceof Error ? error : new Error(String(error)));
|
|
40
294
|
}
|
|
41
295
|
}
|
|
42
296
|
```
|
|
43
297
|
|
|
44
|
-
###
|
|
298
|
+
### 7. Declaration Files
|
|
299
|
+
|
|
45
300
|
```typescript
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
329
|
+
## Use Cases
|
|
330
|
+
|
|
331
|
+
### Type-Safe Redux State
|
|
53
332
|
```typescript
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
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)
|