@musashishao/agent-kit 1.0.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/.agent/.shared/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/.shared/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/.shared/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/.shared/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.agent/.shared/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/jetpack-compose.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/.shared/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/.shared/ui-ux-pro-max/data/styles.csv +59 -0
- package/.agent/.shared/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/.shared/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/.shared/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/.shared/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/core.py +258 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/design_system.py +487 -0
- package/.agent/.shared/ui-ux-pro-max/scripts/search.py +76 -0
- package/.agent/ARCHITECTURE.md +225 -0
- package/.agent/CONTEXT.md +229 -0
- package/.agent/FEATURE_ROADMAP.md +435 -0
- package/.agent/PROMPT_TEMPLATES.md +261 -0
- package/.agent/agents/backend-specialist.md +263 -0
- package/.agent/agents/database-architect.md +226 -0
- package/.agent/agents/debugger.md +225 -0
- package/.agent/agents/devops-engineer.md +242 -0
- package/.agent/agents/documentation-writer.md +104 -0
- package/.agent/agents/explorer-agent.md +73 -0
- package/.agent/agents/frontend-specialist.md +556 -0
- package/.agent/agents/game-developer.md +162 -0
- package/.agent/agents/mobile-developer.md +377 -0
- package/.agent/agents/orchestrator.md +416 -0
- package/.agent/agents/penetration-tester.md +188 -0
- package/.agent/agents/performance-optimizer.md +187 -0
- package/.agent/agents/project-planner.md +403 -0
- package/.agent/agents/security-auditor.md +170 -0
- package/.agent/agents/seo-specialist.md +111 -0
- package/.agent/agents/test-engineer.md +158 -0
- package/.agent/rules/GEMINI.md +251 -0
- package/.agent/skills/api-patterns/SKILL.md +81 -0
- package/.agent/skills/api-patterns/api-style.md +42 -0
- package/.agent/skills/api-patterns/auth.md +24 -0
- package/.agent/skills/api-patterns/documentation.md +26 -0
- package/.agent/skills/api-patterns/graphql.md +41 -0
- package/.agent/skills/api-patterns/rate-limiting.md +31 -0
- package/.agent/skills/api-patterns/response.md +37 -0
- package/.agent/skills/api-patterns/rest.md +40 -0
- package/.agent/skills/api-patterns/scripts/api_validator.py +211 -0
- package/.agent/skills/api-patterns/security-testing.md +122 -0
- package/.agent/skills/api-patterns/trpc.md +41 -0
- package/.agent/skills/api-patterns/versioning.md +22 -0
- package/.agent/skills/app-builder/SKILL.md +75 -0
- package/.agent/skills/app-builder/agent-coordination.md +71 -0
- package/.agent/skills/app-builder/feature-building.md +53 -0
- package/.agent/skills/app-builder/project-detection.md +34 -0
- package/.agent/skills/app-builder/scaffolding.md +118 -0
- package/.agent/skills/app-builder/tech-stack.md +40 -0
- package/.agent/skills/app-builder/templates/SKILL.md +39 -0
- package/.agent/skills/app-builder/templates/astro-static/TEMPLATE.md +76 -0
- package/.agent/skills/app-builder/templates/chrome-extension/TEMPLATE.md +92 -0
- package/.agent/skills/app-builder/templates/cli-tool/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/electron-desktop/TEMPLATE.md +88 -0
- package/.agent/skills/app-builder/templates/express-api/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/flutter-app/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/monorepo-turborepo/TEMPLATE.md +90 -0
- package/.agent/skills/app-builder/templates/nextjs-fullstack/TEMPLATE.md +82 -0
- package/.agent/skills/app-builder/templates/nextjs-saas/TEMPLATE.md +100 -0
- package/.agent/skills/app-builder/templates/nextjs-static/TEMPLATE.md +106 -0
- package/.agent/skills/app-builder/templates/nuxt-app/TEMPLATE.md +101 -0
- package/.agent/skills/app-builder/templates/python-fastapi/TEMPLATE.md +83 -0
- package/.agent/skills/app-builder/templates/react-native-app/TEMPLATE.md +93 -0
- package/.agent/skills/architecture/SKILL.md +55 -0
- package/.agent/skills/architecture/context-discovery.md +43 -0
- package/.agent/skills/architecture/examples.md +94 -0
- package/.agent/skills/architecture/pattern-selection.md +68 -0
- package/.agent/skills/architecture/patterns-reference.md +50 -0
- package/.agent/skills/architecture/trade-off-analysis.md +77 -0
- package/.agent/skills/bash-linux/SKILL.md +199 -0
- package/.agent/skills/behavioral-modes/SKILL.md +242 -0
- package/.agent/skills/brainstorming/SKILL.md +163 -0
- package/.agent/skills/brainstorming/dynamic-questioning.md +350 -0
- package/.agent/skills/clean-code/SKILL.md +201 -0
- package/.agent/skills/code-review-checklist/SKILL.md +109 -0
- package/.agent/skills/database-design/SKILL.md +52 -0
- package/.agent/skills/database-design/database-selection.md +43 -0
- package/.agent/skills/database-design/indexing.md +39 -0
- package/.agent/skills/database-design/migrations.md +48 -0
- package/.agent/skills/database-design/optimization.md +36 -0
- package/.agent/skills/database-design/orm-selection.md +30 -0
- package/.agent/skills/database-design/schema-design.md +56 -0
- package/.agent/skills/database-design/scripts/schema_validator.py +172 -0
- package/.agent/skills/deployment-procedures/SKILL.md +241 -0
- package/.agent/skills/doc.md +177 -0
- package/.agent/skills/docker-expert/SKILL.md +409 -0
- package/.agent/skills/documentation-templates/SKILL.md +194 -0
- package/.agent/skills/frontend-design/SKILL.md +396 -0
- package/.agent/skills/frontend-design/animation-guide.md +331 -0
- package/.agent/skills/frontend-design/color-system.md +311 -0
- package/.agent/skills/frontend-design/decision-trees.md +418 -0
- package/.agent/skills/frontend-design/motion-graphics.md +306 -0
- package/.agent/skills/frontend-design/scripts/accessibility_checker.py +183 -0
- package/.agent/skills/frontend-design/scripts/ux_audit.py +722 -0
- package/.agent/skills/frontend-design/typography-system.md +345 -0
- package/.agent/skills/frontend-design/ux-psychology.md +541 -0
- package/.agent/skills/frontend-design/visual-effects.md +383 -0
- package/.agent/skills/game-development/2d-games/SKILL.md +119 -0
- package/.agent/skills/game-development/3d-games/SKILL.md +135 -0
- package/.agent/skills/game-development/SKILL.md +167 -0
- package/.agent/skills/game-development/game-art/SKILL.md +185 -0
- package/.agent/skills/game-development/game-audio/SKILL.md +190 -0
- package/.agent/skills/game-development/game-design/SKILL.md +129 -0
- package/.agent/skills/game-development/mobile-games/SKILL.md +108 -0
- package/.agent/skills/game-development/multiplayer/SKILL.md +132 -0
- package/.agent/skills/game-development/pc-games/SKILL.md +144 -0
- package/.agent/skills/game-development/vr-ar/SKILL.md +123 -0
- package/.agent/skills/game-development/web-games/SKILL.md +150 -0
- package/.agent/skills/geo-fundamentals/SKILL.md +156 -0
- package/.agent/skills/geo-fundamentals/scripts/geo_checker.py +289 -0
- package/.agent/skills/i18n-localization/SKILL.md +154 -0
- package/.agent/skills/i18n-localization/scripts/i18n_checker.py +241 -0
- package/.agent/skills/lint-and-validate/SKILL.md +45 -0
- package/.agent/skills/lint-and-validate/scripts/lint_runner.py +172 -0
- package/.agent/skills/lint-and-validate/scripts/type_coverage.py +173 -0
- package/.agent/skills/mcp-builder/SKILL.md +176 -0
- package/.agent/skills/mobile-design/SKILL.md +394 -0
- package/.agent/skills/mobile-design/decision-trees.md +516 -0
- package/.agent/skills/mobile-design/mobile-backend.md +491 -0
- package/.agent/skills/mobile-design/mobile-color-system.md +420 -0
- package/.agent/skills/mobile-design/mobile-debugging.md +122 -0
- package/.agent/skills/mobile-design/mobile-design-thinking.md +357 -0
- package/.agent/skills/mobile-design/mobile-navigation.md +458 -0
- package/.agent/skills/mobile-design/mobile-performance.md +767 -0
- package/.agent/skills/mobile-design/mobile-testing.md +356 -0
- package/.agent/skills/mobile-design/mobile-typography.md +433 -0
- package/.agent/skills/mobile-design/platform-android.md +666 -0
- package/.agent/skills/mobile-design/platform-ios.md +561 -0
- package/.agent/skills/mobile-design/scripts/mobile_audit.py +670 -0
- package/.agent/skills/mobile-design/touch-psychology.md +537 -0
- package/.agent/skills/nestjs-expert/SKILL.md +552 -0
- package/.agent/skills/nextjs-best-practices/SKILL.md +203 -0
- package/.agent/skills/nodejs-best-practices/SKILL.md +333 -0
- package/.agent/skills/parallel-agents/SKILL.md +175 -0
- package/.agent/skills/performance-profiling/SKILL.md +143 -0
- package/.agent/skills/performance-profiling/scripts/lighthouse_audit.py +76 -0
- package/.agent/skills/plan-writing/SKILL.md +152 -0
- package/.agent/skills/powershell-windows/SKILL.md +167 -0
- package/.agent/skills/prisma-expert/SKILL.md +355 -0
- package/.agent/skills/python-patterns/SKILL.md +441 -0
- package/.agent/skills/react-patterns/SKILL.md +198 -0
- package/.agent/skills/red-team-tactics/SKILL.md +199 -0
- package/.agent/skills/seo-fundamentals/SKILL.md +129 -0
- package/.agent/skills/seo-fundamentals/scripts/seo_checker.py +219 -0
- package/.agent/skills/server-management/SKILL.md +161 -0
- package/.agent/skills/systematic-debugging/SKILL.md +109 -0
- package/.agent/skills/tailwind-patterns/SKILL.md +269 -0
- package/.agent/skills/tdd-workflow/SKILL.md +149 -0
- package/.agent/skills/testing-patterns/SKILL.md +178 -0
- package/.agent/skills/testing-patterns/scripts/test_runner.py +219 -0
- package/.agent/skills/typescript-expert/SKILL.md +429 -0
- package/.agent/skills/typescript-expert/references/tsconfig-strict.json +92 -0
- package/.agent/skills/typescript-expert/references/typescript-cheatsheet.md +383 -0
- package/.agent/skills/typescript-expert/references/utility-types.ts +335 -0
- package/.agent/skills/typescript-expert/scripts/ts_diagnostic.py +203 -0
- package/.agent/skills/ui-ux-pro-max/SKILL.md +351 -0
- package/.agent/skills/ui-ux-pro-max/data/charts.csv +26 -0
- package/.agent/skills/ui-ux-pro-max/data/colors.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/icons.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/landing.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/data/products.csv +97 -0
- package/.agent/skills/ui-ux-pro-max/data/prompts.csv +24 -0
- package/.agent/skills/ui-ux-pro-max/data/react-performance.csv +45 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/flutter.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/html-tailwind.csv +56 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nextjs.csv +53 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxt-ui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/nuxtjs.csv +59 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react-native.csv +52 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/react.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/shadcn.csv +61 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/svelte.csv +54 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/swiftui.csv +51 -0
- package/.agent/skills/ui-ux-pro-max/data/stacks/vue.csv +50 -0
- package/.agent/skills/ui-ux-pro-max/data/styles.csv +59 -0
- package/.agent/skills/ui-ux-pro-max/data/typography.csv +58 -0
- package/.agent/skills/ui-ux-pro-max/data/ui-reasoning.csv +101 -0
- package/.agent/skills/ui-ux-pro-max/data/ux-guidelines.csv +100 -0
- package/.agent/skills/ui-ux-pro-max/data/web-interface.csv +31 -0
- package/.agent/skills/ui-ux-pro-max/scripts/core.py +257 -0
- package/.agent/skills/ui-ux-pro-max/scripts/design_system.py +487 -0
- package/.agent/skills/ui-ux-pro-max/scripts/search.py +76 -0
- package/.agent/skills/vulnerability-scanner/SKILL.md +276 -0
- package/.agent/skills/vulnerability-scanner/checklists.md +121 -0
- package/.agent/skills/vulnerability-scanner/scripts/security_scan.py +458 -0
- package/.agent/skills/webapp-testing/SKILL.md +187 -0
- package/.agent/skills/webapp-testing/scripts/playwright_runner.py +173 -0
- package/.agent/workflows/brainstorm.md +113 -0
- package/.agent/workflows/create.md +59 -0
- package/.agent/workflows/debug.md +103 -0
- package/.agent/workflows/deploy.md +176 -0
- package/.agent/workflows/enhance.md +63 -0
- package/.agent/workflows/orchestrate.md +237 -0
- package/.agent/workflows/plan.md +89 -0
- package/.agent/workflows/preview.md +80 -0
- package/.agent/workflows/status.md +86 -0
- package/.agent/workflows/test.md +144 -0
- package/.agent/workflows/ui-ux-pro-max.md +231 -0
- package/LICENSE +21 -0
- package/README.md +101 -0
- package/bin/cli.js +235 -0
- package/index.js +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"display": "Strict TypeScript 5.x",
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
// =========================================================================
|
|
6
|
+
// STRICTNESS (Maximum Type Safety)
|
|
7
|
+
// =========================================================================
|
|
8
|
+
"strict": true,
|
|
9
|
+
"noUncheckedIndexedAccess": true,
|
|
10
|
+
"noImplicitOverride": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
12
|
+
"exactOptionalPropertyTypes": true,
|
|
13
|
+
"noFallthroughCasesInSwitch": true,
|
|
14
|
+
"forceConsistentCasingInFileNames": true,
|
|
15
|
+
// =========================================================================
|
|
16
|
+
// MODULE SYSTEM (Modern ESM)
|
|
17
|
+
// =========================================================================
|
|
18
|
+
"module": "ESNext",
|
|
19
|
+
"moduleResolution": "bundler",
|
|
20
|
+
"resolveJsonModule": true,
|
|
21
|
+
"esModuleInterop": true,
|
|
22
|
+
"allowSyntheticDefaultImports": true,
|
|
23
|
+
"isolatedModules": true,
|
|
24
|
+
"verbatimModuleSyntax": true,
|
|
25
|
+
// =========================================================================
|
|
26
|
+
// OUTPUT
|
|
27
|
+
// =========================================================================
|
|
28
|
+
"target": "ES2022",
|
|
29
|
+
"lib": [
|
|
30
|
+
"ES2022",
|
|
31
|
+
"DOM",
|
|
32
|
+
"DOM.Iterable"
|
|
33
|
+
],
|
|
34
|
+
"declaration": true,
|
|
35
|
+
"declarationMap": true,
|
|
36
|
+
"sourceMap": true,
|
|
37
|
+
// =========================================================================
|
|
38
|
+
// PERFORMANCE
|
|
39
|
+
// =========================================================================
|
|
40
|
+
"skipLibCheck": true,
|
|
41
|
+
"incremental": true,
|
|
42
|
+
// =========================================================================
|
|
43
|
+
// PATH ALIASES
|
|
44
|
+
// =========================================================================
|
|
45
|
+
"baseUrl": ".",
|
|
46
|
+
"paths": {
|
|
47
|
+
"@/*": [
|
|
48
|
+
"./src/*"
|
|
49
|
+
],
|
|
50
|
+
"@/components/*": [
|
|
51
|
+
"./src/components/*"
|
|
52
|
+
],
|
|
53
|
+
"@/lib/*": [
|
|
54
|
+
"./src/lib/*"
|
|
55
|
+
],
|
|
56
|
+
"@/types/*": [
|
|
57
|
+
"./src/types/*"
|
|
58
|
+
],
|
|
59
|
+
"@/utils/*": [
|
|
60
|
+
"./src/utils/*"
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
// =========================================================================
|
|
64
|
+
// JSX (for React projects)
|
|
65
|
+
// =========================================================================
|
|
66
|
+
// "jsx": "react-jsx",
|
|
67
|
+
// =========================================================================
|
|
68
|
+
// EMIT
|
|
69
|
+
// =========================================================================
|
|
70
|
+
"noEmit": true, // Let bundler handle emit
|
|
71
|
+
// "outDir": "./dist",
|
|
72
|
+
// "rootDir": "./src",
|
|
73
|
+
// =========================================================================
|
|
74
|
+
// DECORATORS (if needed)
|
|
75
|
+
// =========================================================================
|
|
76
|
+
// "experimentalDecorators": true,
|
|
77
|
+
// "emitDecoratorMetadata": true
|
|
78
|
+
},
|
|
79
|
+
"include": [
|
|
80
|
+
"src/**/*.ts",
|
|
81
|
+
"src/**/*.tsx",
|
|
82
|
+
"src/**/*.d.ts"
|
|
83
|
+
],
|
|
84
|
+
"exclude": [
|
|
85
|
+
"node_modules",
|
|
86
|
+
"dist",
|
|
87
|
+
"build",
|
|
88
|
+
"coverage",
|
|
89
|
+
"**/*.test.ts",
|
|
90
|
+
"**/*.spec.ts"
|
|
91
|
+
]
|
|
92
|
+
}
|
|
@@ -0,0 +1,383 @@
|
|
|
1
|
+
# TypeScript Cheatsheet
|
|
2
|
+
|
|
3
|
+
## Type Basics
|
|
4
|
+
|
|
5
|
+
```typescript
|
|
6
|
+
// Primitives
|
|
7
|
+
const name: string = 'John'
|
|
8
|
+
const age: number = 30
|
|
9
|
+
const isActive: boolean = true
|
|
10
|
+
const nothing: null = null
|
|
11
|
+
const notDefined: undefined = undefined
|
|
12
|
+
|
|
13
|
+
// Arrays
|
|
14
|
+
const numbers: number[] = [1, 2, 3]
|
|
15
|
+
const strings: Array<string> = ['a', 'b', 'c']
|
|
16
|
+
|
|
17
|
+
// Tuple
|
|
18
|
+
const tuple: [string, number] = ['hello', 42]
|
|
19
|
+
|
|
20
|
+
// Object
|
|
21
|
+
const user: { name: string; age: number } = { name: 'John', age: 30 }
|
|
22
|
+
|
|
23
|
+
// Union
|
|
24
|
+
const value: string | number = 'hello'
|
|
25
|
+
|
|
26
|
+
// Literal
|
|
27
|
+
const direction: 'up' | 'down' | 'left' | 'right' = 'up'
|
|
28
|
+
|
|
29
|
+
// Any vs Unknown
|
|
30
|
+
const anyValue: any = 'anything' // ❌ Avoid
|
|
31
|
+
const unknownValue: unknown = 'safe' // ✅ Prefer, requires narrowing
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Type Aliases & Interfaces
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
// Type Alias
|
|
38
|
+
type Point = {
|
|
39
|
+
x: number
|
|
40
|
+
y: number
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Interface (preferred for objects)
|
|
44
|
+
interface User {
|
|
45
|
+
id: string
|
|
46
|
+
name: string
|
|
47
|
+
email?: string // Optional
|
|
48
|
+
readonly createdAt: Date // Readonly
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Extending
|
|
52
|
+
interface Admin extends User {
|
|
53
|
+
permissions: string[]
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Intersection
|
|
57
|
+
type AdminUser = User & { permissions: string[] }
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Generics
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
// Generic function
|
|
64
|
+
function identity<T>(value: T): T {
|
|
65
|
+
return value
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// Generic with constraint
|
|
69
|
+
function getLength<T extends { length: number }>(item: T): number {
|
|
70
|
+
return item.length
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// Generic interface
|
|
74
|
+
interface ApiResponse<T> {
|
|
75
|
+
data: T
|
|
76
|
+
status: number
|
|
77
|
+
message: string
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Generic with default
|
|
81
|
+
type Container<T = string> = {
|
|
82
|
+
value: T
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Multiple generics
|
|
86
|
+
function merge<T, U>(obj1: T, obj2: U): T & U {
|
|
87
|
+
return { ...obj1, ...obj2 }
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Utility Types
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
interface User {
|
|
95
|
+
id: string
|
|
96
|
+
name: string
|
|
97
|
+
email: string
|
|
98
|
+
age: number
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Partial - all optional
|
|
102
|
+
type PartialUser = Partial<User>
|
|
103
|
+
|
|
104
|
+
// Required - all required
|
|
105
|
+
type RequiredUser = Required<User>
|
|
106
|
+
|
|
107
|
+
// Readonly - all readonly
|
|
108
|
+
type ReadonlyUser = Readonly<User>
|
|
109
|
+
|
|
110
|
+
// Pick - select properties
|
|
111
|
+
type UserName = Pick<User, 'id' | 'name'>
|
|
112
|
+
|
|
113
|
+
// Omit - exclude properties
|
|
114
|
+
type UserWithoutEmail = Omit<User, 'email'>
|
|
115
|
+
|
|
116
|
+
// Record - key-value map
|
|
117
|
+
type UserMap = Record<string, User>
|
|
118
|
+
|
|
119
|
+
// Extract - extract from union
|
|
120
|
+
type StringOrNumber = string | number | boolean
|
|
121
|
+
type OnlyStrings = Extract<StringOrNumber, string>
|
|
122
|
+
|
|
123
|
+
// Exclude - exclude from union
|
|
124
|
+
type NotString = Exclude<StringOrNumber, string>
|
|
125
|
+
|
|
126
|
+
// NonNullable - remove null/undefined
|
|
127
|
+
type MaybeString = string | null | undefined
|
|
128
|
+
type DefinitelyString = NonNullable<MaybeString>
|
|
129
|
+
|
|
130
|
+
// ReturnType - get function return type
|
|
131
|
+
function getUser() { return { name: 'John' } }
|
|
132
|
+
type UserReturn = ReturnType<typeof getUser>
|
|
133
|
+
|
|
134
|
+
// Parameters - get function parameters
|
|
135
|
+
type GetUserParams = Parameters<typeof getUser>
|
|
136
|
+
|
|
137
|
+
// Awaited - unwrap Promise
|
|
138
|
+
type ResolvedUser = Awaited<Promise<User>>
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Conditional Types
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
// Basic conditional
|
|
145
|
+
type IsString<T> = T extends string ? true : false
|
|
146
|
+
|
|
147
|
+
// Infer keyword
|
|
148
|
+
type UnwrapPromise<T> = T extends Promise<infer U> ? U : T
|
|
149
|
+
|
|
150
|
+
// Distributive conditional
|
|
151
|
+
type ToArray<T> = T extends any ? T[] : never
|
|
152
|
+
type Result = ToArray<string | number> // string[] | number[]
|
|
153
|
+
|
|
154
|
+
// NonDistributive
|
|
155
|
+
type ToArrayNonDist<T> = [T] extends [any] ? T[] : never
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Template Literal Types
|
|
159
|
+
|
|
160
|
+
```typescript
|
|
161
|
+
type Color = 'red' | 'green' | 'blue'
|
|
162
|
+
type Size = 'small' | 'medium' | 'large'
|
|
163
|
+
|
|
164
|
+
// Combine
|
|
165
|
+
type ColorSize = `${Color}-${Size}`
|
|
166
|
+
// 'red-small' | 'red-medium' | 'red-large' | ...
|
|
167
|
+
|
|
168
|
+
// Event handlers
|
|
169
|
+
type EventName = 'click' | 'focus' | 'blur'
|
|
170
|
+
type EventHandler = `on${Capitalize<EventName>}`
|
|
171
|
+
// 'onClick' | 'onFocus' | 'onBlur'
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Mapped Types
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
// Basic mapped type
|
|
178
|
+
type Optional<T> = {
|
|
179
|
+
[K in keyof T]?: T[K]
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// With key remapping
|
|
183
|
+
type Getters<T> = {
|
|
184
|
+
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K]
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Filter keys
|
|
188
|
+
type OnlyStrings<T> = {
|
|
189
|
+
[K in keyof T as T[K] extends string ? K : never]: T[K]
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Type Guards
|
|
194
|
+
|
|
195
|
+
```typescript
|
|
196
|
+
// typeof guard
|
|
197
|
+
function process(value: string | number) {
|
|
198
|
+
if (typeof value === 'string') {
|
|
199
|
+
return value.toUpperCase() // string
|
|
200
|
+
}
|
|
201
|
+
return value.toFixed(2) // number
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// instanceof guard
|
|
205
|
+
class Dog { bark() {} }
|
|
206
|
+
class Cat { meow() {} }
|
|
207
|
+
|
|
208
|
+
function makeSound(animal: Dog | Cat) {
|
|
209
|
+
if (animal instanceof Dog) {
|
|
210
|
+
animal.bark()
|
|
211
|
+
} else {
|
|
212
|
+
animal.meow()
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// in guard
|
|
217
|
+
interface Bird { fly(): void }
|
|
218
|
+
interface Fish { swim(): void }
|
|
219
|
+
|
|
220
|
+
function move(animal: Bird | Fish) {
|
|
221
|
+
if ('fly' in animal) {
|
|
222
|
+
animal.fly()
|
|
223
|
+
} else {
|
|
224
|
+
animal.swim()
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Custom type guard
|
|
229
|
+
function isString(value: unknown): value is string {
|
|
230
|
+
return typeof value === 'string'
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
// Assertion function
|
|
234
|
+
function assertIsString(value: unknown): asserts value is string {
|
|
235
|
+
if (typeof value !== 'string') {
|
|
236
|
+
throw new Error('Not a string')
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## Discriminated Unions
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
// With type discriminant
|
|
245
|
+
type Success<T> = { type: 'success'; data: T }
|
|
246
|
+
type Error = { type: 'error'; message: string }
|
|
247
|
+
type Loading = { type: 'loading' }
|
|
248
|
+
|
|
249
|
+
type State<T> = Success<T> | Error | Loading
|
|
250
|
+
|
|
251
|
+
function handle<T>(state: State<T>) {
|
|
252
|
+
switch (state.type) {
|
|
253
|
+
case 'success':
|
|
254
|
+
return state.data // T
|
|
255
|
+
case 'error':
|
|
256
|
+
return state.message // string
|
|
257
|
+
case 'loading':
|
|
258
|
+
return null
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// Exhaustive check
|
|
263
|
+
function assertNever(value: never): never {
|
|
264
|
+
throw new Error(`Unexpected value: ${value}`)
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Branded Types
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
// Create branded type
|
|
272
|
+
type Brand<K, T> = K & { __brand: T }
|
|
273
|
+
|
|
274
|
+
type UserId = Brand<string, 'UserId'>
|
|
275
|
+
type OrderId = Brand<string, 'OrderId'>
|
|
276
|
+
|
|
277
|
+
// Constructor functions
|
|
278
|
+
function createUserId(id: string): UserId {
|
|
279
|
+
return id as UserId
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
function createOrderId(id: string): OrderId {
|
|
283
|
+
return id as OrderId
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// Usage - prevents mixing
|
|
287
|
+
function getOrder(orderId: OrderId, userId: UserId) {}
|
|
288
|
+
|
|
289
|
+
const userId = createUserId('user-123')
|
|
290
|
+
const orderId = createOrderId('order-456')
|
|
291
|
+
|
|
292
|
+
getOrder(orderId, userId) // ✅ OK
|
|
293
|
+
// getOrder(userId, orderId) // ❌ Error - types don't match
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
## Module Declarations
|
|
297
|
+
|
|
298
|
+
```typescript
|
|
299
|
+
// Declare module for untyped package
|
|
300
|
+
declare module 'untyped-package' {
|
|
301
|
+
export function doSomething(): void
|
|
302
|
+
export const value: string
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Augment existing module
|
|
306
|
+
declare module 'express' {
|
|
307
|
+
interface Request {
|
|
308
|
+
user?: { id: string }
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// Declare global
|
|
313
|
+
declare global {
|
|
314
|
+
interface Window {
|
|
315
|
+
myGlobal: string
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
## TSConfig Essentials
|
|
321
|
+
|
|
322
|
+
```json
|
|
323
|
+
{
|
|
324
|
+
"compilerOptions": {
|
|
325
|
+
// Strictness
|
|
326
|
+
"strict": true,
|
|
327
|
+
"noUncheckedIndexedAccess": true,
|
|
328
|
+
"noImplicitOverride": true,
|
|
329
|
+
|
|
330
|
+
// Modules
|
|
331
|
+
"module": "ESNext",
|
|
332
|
+
"moduleResolution": "bundler",
|
|
333
|
+
"esModuleInterop": true,
|
|
334
|
+
|
|
335
|
+
// Output
|
|
336
|
+
"target": "ES2022",
|
|
337
|
+
"lib": ["ES2022", "DOM"],
|
|
338
|
+
|
|
339
|
+
// Performance
|
|
340
|
+
"skipLibCheck": true,
|
|
341
|
+
"incremental": true,
|
|
342
|
+
|
|
343
|
+
// Paths
|
|
344
|
+
"baseUrl": ".",
|
|
345
|
+
"paths": {
|
|
346
|
+
"@/*": ["./src/*"]
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
## Best Practices
|
|
353
|
+
|
|
354
|
+
```typescript
|
|
355
|
+
// ✅ Prefer interface for objects
|
|
356
|
+
interface User {
|
|
357
|
+
name: string
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
// ✅ Use const assertions
|
|
361
|
+
const routes = ['home', 'about'] as const
|
|
362
|
+
|
|
363
|
+
// ✅ Use satisfies for validation
|
|
364
|
+
const config = {
|
|
365
|
+
api: 'https://api.example.com'
|
|
366
|
+
} satisfies Record<string, string>
|
|
367
|
+
|
|
368
|
+
// ✅ Use unknown over any
|
|
369
|
+
function parse(input: unknown) {
|
|
370
|
+
if (typeof input === 'string') {
|
|
371
|
+
return JSON.parse(input)
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// ✅ Explicit return types for public APIs
|
|
376
|
+
export function getUser(id: string): User | null {
|
|
377
|
+
// ...
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// ❌ Avoid
|
|
381
|
+
const data: any = fetchData()
|
|
382
|
+
data.anything.goes.wrong // No type safety
|
|
383
|
+
```
|