memory-journal-mcp 7.1.0 → 7.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/README.md +59 -51
- package/dist/{chunk-GW5DYUQJ.js → chunk-GR4T3SRW.js} +139 -100
- package/dist/{chunk-37BQOJDZ.js → chunk-IWKLHSPU.js} +81 -2
- package/dist/{chunk-JEGRDY6W.js → chunk-ORV7ZZOE.js} +357 -51
- package/dist/cli.js +30 -4
- package/dist/github-integration-2TFMXHIJ.js +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +3 -3
- package/dist/{tools-O44Q52RD.js → tools-CXR2FEB2.js} +2 -2
- package/package.json +1 -1
- package/skills/README.md +77 -0
- package/skills/autonomous-dev/SKILL.md +56 -0
- package/skills/bin/sync.js +50 -0
- package/skills/bun/SKILL.md +156 -0
- package/skills/github-commander/SKILL.md +1 -1
- package/skills/github-commander/workflows/code-quality-audit.md +7 -5
- package/skills/github-commander/workflows/issue-triage.md +13 -4
- package/skills/github-commander/workflows/milestone-sprint.md +9 -1
- package/skills/github-commander/workflows/perf-audit.md +2 -0
- package/skills/github-commander/workflows/pr-review.md +9 -3
- package/skills/github-commander/workflows/roadmap-kickoff.md +79 -0
- package/skills/github-commander/workflows/security-audit.md +3 -3
- package/skills/github-commander/workflows/update-deps.md +2 -2
- package/skills/gitlab/SKILL.md +115 -0
- package/skills/gitlab/package-lock.json +392 -0
- package/skills/gitlab/package.json +14 -0
- package/skills/gitlab/scripts/gitlab-client.ts +125 -0
- package/skills/gitlab/scripts/gitlab-helper.ts +80 -0
- package/skills/golang/SKILL.md +54 -0
- package/skills/mysql/SKILL.md +30 -0
- package/skills/package.json +48 -0
- package/skills/playwright-standard/SKILL.md +58 -0
- package/skills/playwright-standard/examples/fixtures.ts +66 -0
- package/skills/playwright-standard/examples/type-stubs.d.ts +10 -0
- package/skills/playwright-standard/references/advanced-scenarios.md +59 -0
- package/skills/playwright-standard/references/infrastructure.md +43 -0
- package/skills/postgres/SKILL.md +33 -0
- package/skills/react-best-practices/AGENTS.md +2883 -0
- package/skills/react-best-practices/README.md +127 -0
- package/skills/react-best-practices/SKILL.md +138 -0
- package/skills/react-best-practices/metadata.json +17 -0
- package/skills/react-best-practices/rules/_sections.md +46 -0
- package/skills/react-best-practices/rules/_template.md +28 -0
- package/skills/react-best-practices/rules/advanced-event-handler-refs.md +55 -0
- package/skills/react-best-practices/rules/advanced-init-once.md +42 -0
- package/skills/react-best-practices/rules/advanced-use-latest.md +39 -0
- package/skills/react-best-practices/rules/async-api-routes.md +35 -0
- package/skills/react-best-practices/rules/async-defer-await.md +80 -0
- package/skills/react-best-practices/rules/async-dependencies.md +48 -0
- package/skills/react-best-practices/rules/async-parallel.md +24 -0
- package/skills/react-best-practices/rules/async-suspense-boundaries.md +99 -0
- package/skills/react-best-practices/rules/bundle-barrel-imports.md +59 -0
- package/skills/react-best-practices/rules/bundle-conditional.md +37 -0
- package/skills/react-best-practices/rules/bundle-defer-third-party.md +48 -0
- package/skills/react-best-practices/rules/bundle-dynamic-imports.md +34 -0
- package/skills/react-best-practices/rules/bundle-preload.md +44 -0
- package/skills/react-best-practices/rules/client-event-listeners.md +78 -0
- package/skills/react-best-practices/rules/client-localstorage-schema.md +74 -0
- package/skills/react-best-practices/rules/client-passive-event-listeners.md +48 -0
- package/skills/react-best-practices/rules/client-swr-dedup.md +56 -0
- package/skills/react-best-practices/rules/js-batch-dom-css.md +110 -0
- package/skills/react-best-practices/rules/js-cache-function-results.md +80 -0
- package/skills/react-best-practices/rules/js-cache-property-access.md +28 -0
- package/skills/react-best-practices/rules/js-cache-storage.md +68 -0
- package/skills/react-best-practices/rules/js-combine-iterations.md +32 -0
- package/skills/react-best-practices/rules/js-early-exit.md +50 -0
- package/skills/react-best-practices/rules/js-hoist-regexp.md +45 -0
- package/skills/react-best-practices/rules/js-index-maps.md +37 -0
- package/skills/react-best-practices/rules/js-length-check-first.md +50 -0
- package/skills/react-best-practices/rules/js-min-max-loop.md +82 -0
- package/skills/react-best-practices/rules/js-set-map-lookups.md +24 -0
- package/skills/react-best-practices/rules/js-tosorted-immutable.md +57 -0
- package/skills/react-best-practices/rules/rendering-activity.md +24 -0
- package/skills/react-best-practices/rules/rendering-animate-svg-wrapper.md +38 -0
- package/skills/react-best-practices/rules/rendering-conditional-render.md +32 -0
- package/skills/react-best-practices/rules/rendering-content-visibility.md +38 -0
- package/skills/react-best-practices/rules/rendering-hoist-jsx.md +36 -0
- package/skills/react-best-practices/rules/rendering-hydration-no-flicker.md +72 -0
- package/skills/react-best-practices/rules/rendering-hydration-suppress-warning.md +26 -0
- package/skills/react-best-practices/rules/rendering-svg-precision.md +28 -0
- package/skills/react-best-practices/rules/rendering-usetransition-loading.md +75 -0
- package/skills/react-best-practices/rules/rerender-defer-reads.md +39 -0
- package/skills/react-best-practices/rules/rerender-dependencies.md +45 -0
- package/skills/react-best-practices/rules/rerender-derived-state-no-effect.md +40 -0
- package/skills/react-best-practices/rules/rerender-derived-state.md +29 -0
- package/skills/react-best-practices/rules/rerender-functional-setstate.md +77 -0
- package/skills/react-best-practices/rules/rerender-lazy-state-init.md +56 -0
- package/skills/react-best-practices/rules/rerender-memo-with-default-value.md +36 -0
- package/skills/react-best-practices/rules/rerender-memo.md +44 -0
- package/skills/react-best-practices/rules/rerender-move-effect-to-event.md +45 -0
- package/skills/react-best-practices/rules/rerender-simple-expression-in-memo.md +35 -0
- package/skills/react-best-practices/rules/rerender-transitions.md +40 -0
- package/skills/react-best-practices/rules/rerender-use-ref-transient-values.md +73 -0
- package/skills/react-best-practices/rules/server-after-nonblocking.md +73 -0
- package/skills/react-best-practices/rules/server-auth-actions.md +96 -0
- package/skills/react-best-practices/rules/server-cache-lru.md +41 -0
- package/skills/react-best-practices/rules/server-cache-react.md +76 -0
- package/skills/react-best-practices/rules/server-dedup-props.md +65 -0
- package/skills/react-best-practices/rules/server-parallel-fetching.md +83 -0
- package/skills/react-best-practices/rules/server-serialization.md +38 -0
- package/skills/rust/SKILL.md +86 -0
- package/skills/shadcn-ui/SKILL.md +72 -0
- package/skills/skill-builder/SKILL.md +457 -0
- package/skills/skill-builder/checklist.md +65 -0
- package/skills/sqlite/SKILL.md +38 -0
- package/skills/typescript/SKILL.md +453 -0
- package/skills/typescript/assets/eslint-template.js +102 -0
- package/skills/typescript/assets/tsconfig-template.json +45 -0
- package/skills/typescript/references/enterprise-patterns.md +531 -0
- package/skills/typescript/references/generics.md +493 -0
- package/skills/typescript/references/nestjs-integration.md +579 -0
- package/skills/typescript/references/react-integration.md +616 -0
- package/skills/typescript/references/toolchain.md +547 -0
- package/skills/typescript/references/type-system.md +481 -0
- package/skills/vitest-standard/SKILL.md +82 -0
- package/skills/vitest-standard/examples/service-mock.ts +60 -0
- package/skills/vitest-standard/examples/tdd-calculator.ts +41 -0
- package/skills/vitest-standard/examples/type-stubs.d.ts +18 -0
- package/skills/vitest-standard/references/async-and-errors.md +58 -0
- package/skills/vitest-standard/references/coverage-and-config.md +53 -0
- package/skills/vitest-standard/references/mocking.md +61 -0
- package/skills/vitest-standard/references/tdd-patterns.md +60 -0
- package/dist/github-integration-FOJ4U6I5.js +0 -1
- package/skills/github-commander/workflows/full-audit.md +0 -134
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: sqlite
|
|
3
|
+
description: Enforced meta-cognitive rules and production configurations for SQLite development.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# SQLite Production Standards
|
|
7
|
+
|
|
8
|
+
SQLite provides lightweight, serverless SQL, but its default configurations are extremely permissive and optimized for backwards compatibility rather than production rigor.
|
|
9
|
+
|
|
10
|
+
Any AI agent interacting with or scaffolding SQLite databases MUST adhere to the following strict guidelines to prevent catastrophic concurrency failures, silent data corruption, or locking issues.
|
|
11
|
+
|
|
12
|
+
## Concurrency & Performance (Critical Mandates)
|
|
13
|
+
|
|
14
|
+
SQLite only permits one writer at a time. To prevent random `SQLITE_BUSY` errors and enable high-performance read-while-writing:
|
|
15
|
+
|
|
16
|
+
- **Enable WAL Mode**: You must execute `PRAGMA journal_mode=WAL;` immediately upon connection. Ensure the `-wal` and `-shm` sidecar files are managed alongside the main `.db` file.
|
|
17
|
+
- **Configure Timeouts**: Set `PRAGMA busy_timeout=5000;` so writers wait up to 5 seconds before failing.
|
|
18
|
+
- **Early Lock Acquisition**: Use `BEGIN IMMEDIATE;` to grab the write lock early and prevent deadlocks in read-then-write batch patterns.
|
|
19
|
+
- **Synchronization**: `PRAGMA synchronous=NORMAL;` provides the best balance of safety and speed while in WAL mode.
|
|
20
|
+
|
|
21
|
+
## Data Integrity & Type Safety
|
|
22
|
+
|
|
23
|
+
SQLite's default type system uses "Type Affinity" (it will happily accept the string "hello" in an `INTEGER` column) and ignores foreign keys.
|
|
24
|
+
|
|
25
|
+
- **Foreign Keys**: You MUST execute `PRAGMA foreign_keys=ON;` on every single new database connection. It is not persisted. Without this, `ON DELETE CASCADE` fails silently.
|
|
26
|
+
- **Strict Typing**: For all new tables, you MUST append `STRICT` to the `CREATE TABLE` statement (e.g., `CREATE TABLE users (...) STRICT;`) to enforce real data types.
|
|
27
|
+
- **Date/Time Handling**: There is no native DATE/TIME type. Standardize on `TEXT` (ISO8601) or `INTEGER` (Unix timestamp).
|
|
28
|
+
- **Booleans**: Do not use `BOOLEAN`. Use `INTEGER` (0/1). `TRUE` and `FALSE` are just aliases.
|
|
29
|
+
|
|
30
|
+
## Schema Modifications & Transactions
|
|
31
|
+
|
|
32
|
+
- **Alter Table Limitations**: `ALTER TABLE` is extremely limited. To perform complex schema migrations, you must wrap the operation in a transaction: create a new table, copy the data over, drop the old table, and rename the new one.
|
|
33
|
+
- **Batch Modifying**: Autocommit is ON by default. If you are inserting or modifying multiple rows, you MUST batch them in a transaction (`BEGIN; ... COMMIT;`) to achieve 10x-100x speedups.
|
|
34
|
+
|
|
35
|
+
## Maintenance & Backups
|
|
36
|
+
|
|
37
|
+
- **Vacuuming**: Deleted data does not shrink the `.db` file. After bulk deletes, run `VACUUM;` to reclaim space. Ensure the host system has at least 2x the database size in temporary disk space.
|
|
38
|
+
- **Safety**: NEVER blindly copy an open `.db` file using standard OS commands, as it will corrupt if a write is in progress. Use the `.backup` command in the CLI, the native backup API, or `VACUUM INTO 'backup.db'`.
|
|
@@ -0,0 +1,453 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: typescript
|
|
3
|
+
description: |
|
|
4
|
+
Master enterprise-grade TypeScript development with type-safe patterns, modern tooling, and framework integration. This skill provides comprehensive guidance for TypeScript 6.0+, covering type system fundamentals (generics, mapped types, conditional types, satisfies operator), enterprise patterns (error handling, validation with Zod), React integration for type-safe frontends, NestJS for scalable APIs, and LangChain.js for AI applications. Use when building type-safe applications, migrating JavaScript codebases, configuring modern toolchains (Vite 7, pnpm, ESLint, Vitest), implementing advanced type patterns, or comparing TypeScript with Java/Python approaches.
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
category: programming-languages
|
|
7
|
+
triggers:
|
|
8
|
+
- typescript
|
|
9
|
+
- ts
|
|
10
|
+
- type-safe
|
|
11
|
+
- generics
|
|
12
|
+
- nestjs typescript
|
|
13
|
+
- react typescript
|
|
14
|
+
- typescript migration
|
|
15
|
+
- tsconfig
|
|
16
|
+
- type guards
|
|
17
|
+
- mapped types
|
|
18
|
+
- conditional types
|
|
19
|
+
- satisfies operator
|
|
20
|
+
- zod validation
|
|
21
|
+
author: Richard Hightower
|
|
22
|
+
license: MIT
|
|
23
|
+
tags:
|
|
24
|
+
- typescript
|
|
25
|
+
- type-safety
|
|
26
|
+
- enterprise
|
|
27
|
+
- react
|
|
28
|
+
- nestjs
|
|
29
|
+
- langchain
|
|
30
|
+
- vite
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
# Mastering Modern TypeScript
|
|
34
|
+
|
|
35
|
+
Build enterprise-grade, type-safe applications with TypeScript 6.0+.
|
|
36
|
+
|
|
37
|
+
> **Compatibility:** TypeScript 6.0+, Node.js 25.3+, Vite 7, NestJS 11, React 19
|
|
38
|
+
|
|
39
|
+
## TypeScript 6.0 Modernization
|
|
40
|
+
|
|
41
|
+
Released in March 2026, TypeScript 6.0 acts as the final JavaScript-based bridge prior to the TS 7.0 native Go compiler transition:
|
|
42
|
+
|
|
43
|
+
- **Build Performance Defaults**: `strict: true` and `types: []` are now generated by default (no automatic crawling of `@types` to drastically reduce cold start compilation).
|
|
44
|
+
- **Core API Enhancements**: Standard typings added for `Temporal` API, Map "Upsert" (`getOrInsert`), and `RegExp.escape`.
|
|
45
|
+
- **Go Migration Compliance**: Adopt the new `--stableTypeOrdering` flag to preemptively map legacy TS shapes to the future TS 7.0 AST parser.
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Initialize TypeScript project with ESM
|
|
51
|
+
pnpm create vite@latest my-app --template vanilla-ts
|
|
52
|
+
cd my-app && pnpm install
|
|
53
|
+
|
|
54
|
+
# Configure strict TypeScript
|
|
55
|
+
cat > tsconfig.json << 'EOF'
|
|
56
|
+
{
|
|
57
|
+
"compilerOptions": {
|
|
58
|
+
"target": "ES2024",
|
|
59
|
+
"module": "ESNext",
|
|
60
|
+
"moduleResolution": "bundler",
|
|
61
|
+
"strict": true,
|
|
62
|
+
"noUncheckedIndexedAccess": true,
|
|
63
|
+
"exactOptionalPropertyTypes": true,
|
|
64
|
+
"esModuleInterop": true,
|
|
65
|
+
"skipLibCheck": true
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
EOF
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
## When to Use This Skill
|
|
72
|
+
|
|
73
|
+
Use when:
|
|
74
|
+
|
|
75
|
+
- Building type-safe React, NestJS, or Node.js applications
|
|
76
|
+
- Migrating JavaScript codebases to TypeScript
|
|
77
|
+
- Implementing advanced type patterns (generics, mapped types, conditional types)
|
|
78
|
+
- Configuring modern TypeScript toolchains (Vite, pnpm, ESLint)
|
|
79
|
+
- Designing type-safe API contracts with Zod validation
|
|
80
|
+
- Comparing TypeScript approaches with Java or Python
|
|
81
|
+
|
|
82
|
+
## Project Setup Checklist
|
|
83
|
+
|
|
84
|
+
Before starting any TypeScript project:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
- [ ] Use pnpm for package management (faster, disk-efficient)
|
|
88
|
+
- [ ] Configure ESM-first (type: "module" in package.json)
|
|
89
|
+
- [ ] Enable strict mode in tsconfig.json
|
|
90
|
+
- [ ] Set up ESLint with @typescript-eslint
|
|
91
|
+
- [ ] Add Prettier for consistent formatting
|
|
92
|
+
- [ ] Configure Vitest for testing
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Type System Quick Reference
|
|
96
|
+
|
|
97
|
+
### Primitive Types
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
const name: string = 'Alice'
|
|
101
|
+
const age: number = 30
|
|
102
|
+
const active: boolean = true
|
|
103
|
+
const id: bigint = 9007199254740991n
|
|
104
|
+
const key: symbol = Symbol('unique')
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### Union and Intersection Types
|
|
108
|
+
|
|
109
|
+
```typescript
|
|
110
|
+
// Union: value can be one of several types
|
|
111
|
+
type Status = 'pending' | 'approved' | 'rejected'
|
|
112
|
+
|
|
113
|
+
// Intersection: value must satisfy all types
|
|
114
|
+
type Employee = Person & { employeeId: string }
|
|
115
|
+
|
|
116
|
+
// Discriminated union for type-safe handling
|
|
117
|
+
type Result<T> = { success: true; data: T } | { success: false; error: string }
|
|
118
|
+
|
|
119
|
+
function handleResult<T>(result: Result<T>): T | null {
|
|
120
|
+
if (result.success) {
|
|
121
|
+
return result.data // TypeScript knows data exists here
|
|
122
|
+
}
|
|
123
|
+
console.error(result.error)
|
|
124
|
+
return null
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
### Type Guards
|
|
129
|
+
|
|
130
|
+
```typescript
|
|
131
|
+
// typeof guard
|
|
132
|
+
function process(value: string | number): string {
|
|
133
|
+
if (typeof value === 'string') {
|
|
134
|
+
return value.toUpperCase()
|
|
135
|
+
}
|
|
136
|
+
return value.toFixed(2)
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Custom type guard
|
|
140
|
+
interface User {
|
|
141
|
+
type: 'user'
|
|
142
|
+
name: string
|
|
143
|
+
}
|
|
144
|
+
interface Admin {
|
|
145
|
+
type: 'admin'
|
|
146
|
+
permissions: string[]
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function isAdmin(person: User | Admin): person is Admin {
|
|
150
|
+
return person.type === 'admin'
|
|
151
|
+
}
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
### The `satisfies` Operator (TS 5.0+)
|
|
155
|
+
|
|
156
|
+
Validate type conformance while preserving inference:
|
|
157
|
+
|
|
158
|
+
```typescript
|
|
159
|
+
// Problem: Type assertion loses specific type info
|
|
160
|
+
const colors1 = {
|
|
161
|
+
red: '#ff0000',
|
|
162
|
+
green: '#00ff00',
|
|
163
|
+
} as Record<string, string>
|
|
164
|
+
|
|
165
|
+
colors1.red.toUpperCase() // OK, but red could be undefined
|
|
166
|
+
|
|
167
|
+
// Solution: satisfies preserves literal types
|
|
168
|
+
const colors2 = {
|
|
169
|
+
red: '#ff0000',
|
|
170
|
+
green: '#00ff00',
|
|
171
|
+
} satisfies Record<string, string>
|
|
172
|
+
|
|
173
|
+
colors2.red.toUpperCase() // OK, and TypeScript knows red exists
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
## Generics Patterns
|
|
177
|
+
|
|
178
|
+
### Basic Generic Function
|
|
179
|
+
|
|
180
|
+
```typescript
|
|
181
|
+
function first<T>(items: T[]): T | undefined {
|
|
182
|
+
return items[0]
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const num = first([1, 2, 3]) // number | undefined
|
|
186
|
+
const str = first(['a', 'b']) // string | undefined
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
### Constrained Generics
|
|
190
|
+
|
|
191
|
+
```typescript
|
|
192
|
+
interface HasLength {
|
|
193
|
+
length: number
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function logLength<T extends HasLength>(item: T): T {
|
|
197
|
+
console.log(item.length)
|
|
198
|
+
return item
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
logLength('hello') // OK: string has length
|
|
202
|
+
logLength([1, 2, 3]) // OK: array has length
|
|
203
|
+
logLength(42) // Error: number has no length
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
### Generic API Response Wrapper
|
|
207
|
+
|
|
208
|
+
```typescript
|
|
209
|
+
interface ApiResponse<T> {
|
|
210
|
+
data: T
|
|
211
|
+
status: number
|
|
212
|
+
timestamp: Date
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
async function fetchUser(id: string): Promise<ApiResponse<User>> {
|
|
216
|
+
const response = await fetch(`/api/users/${id}`)
|
|
217
|
+
const data = await response.json()
|
|
218
|
+
return {
|
|
219
|
+
data,
|
|
220
|
+
status: response.status,
|
|
221
|
+
timestamp: new Date(),
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
## Utility Types Reference
|
|
227
|
+
|
|
228
|
+
| Type | Purpose | Example |
|
|
229
|
+
| --------------- | ----------------------------- | ---------------------------- |
|
|
230
|
+
| `Partial<T>` | All properties optional | `Partial<User>` |
|
|
231
|
+
| `Required<T>` | All properties required | `Required<Config>` |
|
|
232
|
+
| `Pick<T, K>` | Select specific properties | `Pick<User, "id" \| "name">` |
|
|
233
|
+
| `Omit<T, K>` | Exclude specific properties | `Omit<User, "password">` |
|
|
234
|
+
| `Record<K, V>` | Object with typed keys/values | `Record<string, number>` |
|
|
235
|
+
| `ReturnType<F>` | Extract function return type | `ReturnType<typeof fn>` |
|
|
236
|
+
| `Parameters<F>` | Extract function parameters | `Parameters<typeof fn>` |
|
|
237
|
+
| `Awaited<T>` | Unwrap Promise type | `Awaited<Promise<User>>` |
|
|
238
|
+
|
|
239
|
+
## Conditional Types
|
|
240
|
+
|
|
241
|
+
```typescript
|
|
242
|
+
// Basic conditional type
|
|
243
|
+
type IsString<T> = T extends string ? true : false
|
|
244
|
+
|
|
245
|
+
// Extract array element type
|
|
246
|
+
type ArrayElement<T> = T extends (infer E)[] ? E : never
|
|
247
|
+
|
|
248
|
+
type Numbers = ArrayElement<number[]> // number
|
|
249
|
+
type Strings = ArrayElement<string[]> // string
|
|
250
|
+
|
|
251
|
+
// Practical: Extract Promise result type
|
|
252
|
+
type UnwrapPromise<T> = T extends Promise<infer R> ? R : T
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Mapped Types
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
// Make all properties readonly
|
|
259
|
+
type Immutable<T> = {
|
|
260
|
+
readonly [K in keyof T]: T[K]
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
// Make all properties nullable
|
|
264
|
+
type Nullable<T> = {
|
|
265
|
+
[K in keyof T]: T[K] | null
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
// Create getter functions for each property
|
|
269
|
+
type Getters<T> = {
|
|
270
|
+
[K in keyof T as `get${Capitalize<string & K>}`]: () => T[K]
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
interface Person {
|
|
274
|
+
name: string
|
|
275
|
+
age: number
|
|
276
|
+
}
|
|
277
|
+
type PersonGetters = Getters<Person>
|
|
278
|
+
// { getName: () => string; getAge: () => number }
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Framework Integration
|
|
282
|
+
|
|
283
|
+
### React with TypeScript
|
|
284
|
+
|
|
285
|
+
```typescript
|
|
286
|
+
// Typed functional component
|
|
287
|
+
interface ButtonProps {
|
|
288
|
+
label: string;
|
|
289
|
+
onClick: () => void;
|
|
290
|
+
variant?: "primary" | "secondary";
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
const Button: React.FC<ButtonProps> = ({ label, onClick, variant = "primary" }) => (
|
|
294
|
+
<button className={variant} onClick={onClick}>
|
|
295
|
+
{label}
|
|
296
|
+
</button>
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// Typed hooks
|
|
300
|
+
const [count, setCount] = useState<number>(0);
|
|
301
|
+
const userRef = useRef<HTMLInputElement>(null);
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### NestJS with TypeScript
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
// Type-safe DTO with class-validator
|
|
308
|
+
import { IsString, IsEmail, MinLength } from 'class-validator'
|
|
309
|
+
|
|
310
|
+
class CreateUserDto {
|
|
311
|
+
@IsString()
|
|
312
|
+
@MinLength(2)
|
|
313
|
+
name: string
|
|
314
|
+
|
|
315
|
+
@IsEmail()
|
|
316
|
+
email: string
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Or with Zod (modern approach)
|
|
320
|
+
import { z } from 'zod'
|
|
321
|
+
|
|
322
|
+
const CreateUserSchema = z.object({
|
|
323
|
+
name: z.string().min(2),
|
|
324
|
+
email: z.string().email(),
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
type CreateUserDto = z.infer<typeof CreateUserSchema>
|
|
328
|
+
```
|
|
329
|
+
|
|
330
|
+
See [react-integration.md](references/react-integration.md) and [nestjs-integration.md](references/nestjs-integration.md) for detailed patterns.
|
|
331
|
+
|
|
332
|
+
## Validation with Zod
|
|
333
|
+
|
|
334
|
+
```typescript
|
|
335
|
+
import { z } from 'zod'
|
|
336
|
+
|
|
337
|
+
// Define schema
|
|
338
|
+
const UserSchema = z.object({
|
|
339
|
+
id: z.string().uuid(),
|
|
340
|
+
name: z.string().min(1).max(100),
|
|
341
|
+
email: z.string().email(),
|
|
342
|
+
role: z.enum(['user', 'admin', 'moderator']),
|
|
343
|
+
createdAt: z.coerce.date(),
|
|
344
|
+
})
|
|
345
|
+
|
|
346
|
+
// Infer TypeScript type from schema
|
|
347
|
+
type User = z.infer<typeof UserSchema>
|
|
348
|
+
|
|
349
|
+
// Validate at runtime
|
|
350
|
+
function parseUser(data: unknown): User {
|
|
351
|
+
return UserSchema.parse(data) // Throws ZodError if invalid
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// Safe parsing (returns result object)
|
|
355
|
+
const result = UserSchema.safeParse(data)
|
|
356
|
+
if (result.success) {
|
|
357
|
+
console.log(result.data) // Typed as User
|
|
358
|
+
} else {
|
|
359
|
+
console.error(result.error.issues)
|
|
360
|
+
}
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
## Modern Toolchain (2025)
|
|
364
|
+
|
|
365
|
+
| Tool | Version | Purpose |
|
|
366
|
+
| ---------- | ------- | ----------------------------- |
|
|
367
|
+
| TypeScript | 6.0+ | Type checking and compilation |
|
|
368
|
+
| Node.js | 25.3+ | Runtime environment |
|
|
369
|
+
| Vite | 7.x | Build tool and dev server |
|
|
370
|
+
| pnpm | 9.x | Package manager |
|
|
371
|
+
| ESLint | 9.x | Linting with flat config |
|
|
372
|
+
| Vitest | 3.x | Testing framework |
|
|
373
|
+
| Prettier | 3.x | Code formatting |
|
|
374
|
+
|
|
375
|
+
### ESLint Flat Config (ESLint 9+)
|
|
376
|
+
|
|
377
|
+
```javascript
|
|
378
|
+
// eslint.config.js
|
|
379
|
+
import eslint from '@eslint/js'
|
|
380
|
+
import tseslint from 'typescript-eslint'
|
|
381
|
+
|
|
382
|
+
export default tseslint.config(eslint.configs.recommended, ...tseslint.configs.strictTypeChecked, {
|
|
383
|
+
languageOptions: {
|
|
384
|
+
parserOptions: {
|
|
385
|
+
projectService: true,
|
|
386
|
+
tsconfigRootDir: import.meta.dirname,
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
})
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Migration Strategies
|
|
393
|
+
|
|
394
|
+
### Incremental Migration
|
|
395
|
+
|
|
396
|
+
1. Add `allowJs: true` and `checkJs: false` to tsconfig.json
|
|
397
|
+
2. Rename files from `.js` to `.ts` one at a time
|
|
398
|
+
3. Add type annotations gradually
|
|
399
|
+
4. Enable stricter options incrementally
|
|
400
|
+
|
|
401
|
+
### JSDoc for Gradual Typing
|
|
402
|
+
|
|
403
|
+
```javascript
|
|
404
|
+
// Before full migration, use JSDoc
|
|
405
|
+
/**
|
|
406
|
+
* @param {string} name
|
|
407
|
+
* @param {number} age
|
|
408
|
+
* @returns {User}
|
|
409
|
+
*/
|
|
410
|
+
function createUser(name, age) {
|
|
411
|
+
return { name, age }
|
|
412
|
+
}
|
|
413
|
+
```
|
|
414
|
+
|
|
415
|
+
See [enterprise-patterns.md](references/enterprise-patterns.md) for comprehensive migration guides.
|
|
416
|
+
|
|
417
|
+
## Common Mistakes
|
|
418
|
+
|
|
419
|
+
| Mistake | Problem | Fix |
|
|
420
|
+
| ----------------------- | -------------------------- | -------------------------- |
|
|
421
|
+
| Using `any` liberally | Defeats type safety | Use `unknown` and narrow |
|
|
422
|
+
| Ignoring strict mode | Misses null/undefined bugs | Enable all strict options |
|
|
423
|
+
| Type assertions (`as`) | Can hide type errors | Use `satisfies` or guards |
|
|
424
|
+
| Enum for simple unions | Generates runtime code | Use literal unions instead |
|
|
425
|
+
| Not validating API data | Runtime type mismatches | Use Zod at boundaries |
|
|
426
|
+
|
|
427
|
+
## Cross-Language Comparison
|
|
428
|
+
|
|
429
|
+
| Feature | TypeScript | Java | Python |
|
|
430
|
+
| ----------- | ---------------------- | ----------------------- | --------------------- |
|
|
431
|
+
| Type System | Structural | Nominal | Gradual (duck typing) |
|
|
432
|
+
| Nullability | Explicit (`T \| null`) | `@Nullable` annotations | Optional via typing |
|
|
433
|
+
| Generics | Type-level, erased | Type-level, erased | Runtime via typing |
|
|
434
|
+
| Interfaces | Structural matching | Must implement | Protocol (3.8+) |
|
|
435
|
+
| Enums | Avoid (use unions) | First-class | Enum class |
|
|
436
|
+
|
|
437
|
+
## Reference Files
|
|
438
|
+
|
|
439
|
+
- [type-system.md](references/type-system.md) — Complete type system guide
|
|
440
|
+
- [generics.md](references/generics.md) — Advanced generics patterns
|
|
441
|
+
- [enterprise-patterns.md](references/enterprise-patterns.md) — Error handling, validation, architecture
|
|
442
|
+
- [react-integration.md](references/react-integration.md) — React + TypeScript patterns
|
|
443
|
+
- [nestjs-integration.md](references/nestjs-integration.md) — NestJS API development
|
|
444
|
+
- [toolchain.md](references/toolchain.md) — Modern build tools configuration
|
|
445
|
+
|
|
446
|
+
## Assets
|
|
447
|
+
|
|
448
|
+
- [tsconfig-template.json](assets/tsconfig-template.json) — Strict enterprise config
|
|
449
|
+
- [eslint-template.js](assets/eslint-template.js) — ESLint 9 flat config
|
|
450
|
+
|
|
451
|
+
## Scripts
|
|
452
|
+
|
|
453
|
+
- [validate-setup.sh](scripts/validate-setup.sh) — Verify TypeScript environment
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// eslint.config.js - ESLint 9+ Flat Config for TypeScript
|
|
2
|
+
// Copy this file to your project root as eslint.config.js
|
|
3
|
+
|
|
4
|
+
import eslint from '@eslint/js'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
import { fileURLToPath } from 'node:url'
|
|
7
|
+
import { dirname } from 'node:path'
|
|
8
|
+
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
|
|
11
|
+
export default tseslint.config(
|
|
12
|
+
// Base ESLint recommendations
|
|
13
|
+
eslint.configs.recommended,
|
|
14
|
+
|
|
15
|
+
// TypeScript strict type-checking
|
|
16
|
+
...tseslint.configs.strictTypeChecked,
|
|
17
|
+
...tseslint.configs.stylisticTypeChecked,
|
|
18
|
+
|
|
19
|
+
// TypeScript parser configuration
|
|
20
|
+
{
|
|
21
|
+
languageOptions: {
|
|
22
|
+
parserOptions: {
|
|
23
|
+
projectService: true,
|
|
24
|
+
tsconfigRootDir: __dirname,
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
// Custom TypeScript rules
|
|
30
|
+
{
|
|
31
|
+
rules: {
|
|
32
|
+
// Allow unused vars with underscore prefix
|
|
33
|
+
'@typescript-eslint/no-unused-vars': [
|
|
34
|
+
'error',
|
|
35
|
+
{
|
|
36
|
+
argsIgnorePattern: '^_',
|
|
37
|
+
varsIgnorePattern: '^_',
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
|
|
41
|
+
// Enforce type imports for better tree-shaking
|
|
42
|
+
'@typescript-eslint/consistent-type-imports': [
|
|
43
|
+
'error',
|
|
44
|
+
{
|
|
45
|
+
prefer: 'type-imports',
|
|
46
|
+
fixStyle: 'inline-type-imports',
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
|
|
50
|
+
// Prevent unhandled promises
|
|
51
|
+
'@typescript-eslint/no-floating-promises': 'error',
|
|
52
|
+
'@typescript-eslint/no-misused-promises': 'error',
|
|
53
|
+
|
|
54
|
+
// Prevent awaiting non-promises
|
|
55
|
+
'@typescript-eslint/await-thenable': 'error',
|
|
56
|
+
|
|
57
|
+
// Prefer nullish coalescing
|
|
58
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'error',
|
|
59
|
+
|
|
60
|
+
// Prefer optional chaining
|
|
61
|
+
'@typescript-eslint/prefer-optional-chain': 'error',
|
|
62
|
+
|
|
63
|
+
// Consistent type assertions
|
|
64
|
+
'@typescript-eslint/consistent-type-assertions': [
|
|
65
|
+
'error',
|
|
66
|
+
{
|
|
67
|
+
assertionStyle: 'as',
|
|
68
|
+
objectLiteralTypeAssertions: 'never',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
|
|
72
|
+
// Naming conventions
|
|
73
|
+
'@typescript-eslint/naming-convention': [
|
|
74
|
+
'error',
|
|
75
|
+
{
|
|
76
|
+
selector: 'interface',
|
|
77
|
+
format: ['PascalCase'],
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
selector: 'typeAlias',
|
|
81
|
+
format: ['PascalCase'],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
selector: 'enum',
|
|
85
|
+
format: ['PascalCase'],
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
// Ignore patterns
|
|
92
|
+
{
|
|
93
|
+
ignores: [
|
|
94
|
+
'dist/**',
|
|
95
|
+
'build/**',
|
|
96
|
+
'node_modules/**',
|
|
97
|
+
'coverage/**',
|
|
98
|
+
'*.config.js',
|
|
99
|
+
'*.config.ts',
|
|
100
|
+
],
|
|
101
|
+
}
|
|
102
|
+
)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// Language and Environment
|
|
5
|
+
"target": "ES2024",
|
|
6
|
+
"lib": ["ES2024"],
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"moduleResolution": "bundler",
|
|
9
|
+
|
|
10
|
+
// Strict Type Checking (Enterprise-Grade)
|
|
11
|
+
"strict": true,
|
|
12
|
+
"noUncheckedIndexedAccess": true,
|
|
13
|
+
"exactOptionalPropertyTypes": true,
|
|
14
|
+
"noImplicitOverride": true,
|
|
15
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
16
|
+
"noFallthroughCasesInSwitch": true,
|
|
17
|
+
"forceConsistentCasingInFileNames": true,
|
|
18
|
+
|
|
19
|
+
// Module Handling
|
|
20
|
+
"esModuleInterop": true,
|
|
21
|
+
"allowSyntheticDefaultImports": true,
|
|
22
|
+
"isolatedModules": true,
|
|
23
|
+
"verbatimModuleSyntax": true,
|
|
24
|
+
|
|
25
|
+
// Output
|
|
26
|
+
"declaration": true,
|
|
27
|
+
"declarationMap": true,
|
|
28
|
+
"sourceMap": true,
|
|
29
|
+
"outDir": "./dist",
|
|
30
|
+
"rootDir": "./src",
|
|
31
|
+
|
|
32
|
+
// Path Aliases (adjust as needed)
|
|
33
|
+
"baseUrl": ".",
|
|
34
|
+
"paths": {
|
|
35
|
+
"@/*": ["./src/*"]
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
// Performance
|
|
39
|
+
"skipLibCheck": true,
|
|
40
|
+
"incremental": true,
|
|
41
|
+
"tsBuildInfoFile": "./node_modules/.cache/tsbuildinfo"
|
|
42
|
+
},
|
|
43
|
+
"include": ["src/**/*"],
|
|
44
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
45
|
+
}
|