docs(adr): ADR-0011: TypeScript for Reference Implementation Scripts
@aRustyDev đang làm issue này rồi.
Từ ngày 5/1/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
ADR-0011: TypeScript for Reference Implementation Scripts
Status
Accepted
Context
ADR-0010 establishes that mdbook-htmx generates server-side reference scripts. This ADR addresses the language choice: TypeScript vs JavaScript.
Decision Drivers
- Self-Documentation - Types describe manifest schema without separate docs
- Error Prevention - Catch type mismatches at compile time
- IDE Support - Autocomplete, refactoring, go-to-definition
- Runtime Compatibility - Must work in Workers, Node, Deno, Bun
- User Accessibility - Not all users know TypeScript
Options Considered
Option A: JavaScript Only
Plain JavaScript with JSDoc comments for types.
/**
* @param {import('./types').User | null} user
* @param {import('./types').Page} page
* @returns {boolean}
*/
function isAuthorized(user, page) {
return page.auth.access === 'public' || user !== null;
}
Pros:
- No build step
- Universally understood
- Runs directly in Node
Cons:
- Types are comments, not enforced
- Verbose JSDoc for complex types
- Less IDE support than native TS
Option B: TypeScript (Recommended)
TypeScript with explicit types.
import type { User, Page } from './types';
function isAuthorized(user: User | null, page: Page): boolean {
return page.auth.access === 'public' || user !== null;
}
Pros:
- Types are enforced
- Self-documenting
- Excellent IDE support
- Catches errors before runtime
- Industry standard for server-side code
Cons:
- Requires build step
- Learning curve for some users
Option C: Both (Generate TS, Transpile to JS)
Generate TypeScript, also include transpiled JavaScript.
book/htmx/scripts/
├── src/ # TypeScript source
│ └── *.ts
├── dist/ # Transpiled JavaScript
│ └── *.js
└── types/ # Declaration files
└── *.d.ts
Pros:
- TypeScript users get native TS
- JavaScript users get working code
- Type definitions available for both
Cons:
- Larger output
- Two versions to maintain conceptually
Decision
TypeScript as default, with JavaScript output option.
Default configuration:
[output.htmx.scripts]
language = "typescript"
emit-js = false # Also emit transpiled JS
emit-declarations = true # Emit .d.ts files
Users can set language = "javascript" for plain JS output with JSDoc.
Rationale
-
Types Document the Manifest
// Types ARE the documentation interface Page { auth: { access: 'public' | 'authenticated' | 'roles'; roles?: string[]; }; }Users reading the code understand the manifest structure without separate docs.
-
Cloudflare Workers Natively Supports TypeScript
# wrangler handles TypeScript automatically wrangler deployNo separate build step for the primary deployment target.
-
Error Prevention
// Caught at compile time if (page.auth.access === 'admin') { // Error: 'admin' not in union type -
Modern Standard
TypeScript is the de facto standard for:
- Cloudflare Workers
- Deno (native support)
- Node.js server applications
- Most modern web frameworks
Bundle Size Considerations
TypeScript transpiles to JavaScript with zero runtime overhead:
| Metric | TypeScript | Transpiled JS |
|---|---|---|
| Bundle size | N/A (source) | Same as hand-written JS |
| Runtime perf | N/A | Identical |
| Types at runtime | Erased | None |
The type imports are completely removed:
// Source
import type { Page } from './types';
// Transpiled - import disappears
Configuration
[output.htmx.scripts]
enabled = true
language = "typescript" # typescript | javascript
# TypeScript options
target = "es2022" # ECMAScript target
module = "esm" # esm | commonjs
strict = true # Strict type checking
emit-js = false # Also generate .js files
emit-declarations = true # Generate .d.ts files
Consequences
Positive
- Types serve as schema documentation
- Compile-time error catching
- Better IDE experience
- Industry-standard choice
- Native Workers/Deno support
Negative
- Some users unfamiliar with TypeScript
- Build step required for Node.js (unless using ts-node)
Mitigation
- Include transpiled JS as option (
emit-js = true) - Provide tsconfig.json with recommended settings
- Document common TypeScript patterns
References
- Ngôn ngữ chính
- Rust
- Star
- 0
- Fork
- 1
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aRustyDev/mdbook-htmx
-
feat(ci): Implement cross-repo-validate compliance for docs syncCó thể làm lại được @aRustyDev đã nhận 285 ngày trước và không có pull request nào đang mở. Đang mởci enhancement
aRustyDev/mdbook-htmx#58 · 1 bình luận · 1 người được giao ·
-
docs(htmx): Explain how HTMX worksCó thể làm lại được @aRustyDev đã nhận 287 ngày trước và không có pull request nào đang mở. Đang mở
aRustyDev/mdbook-htmx#48 · 3 bình luận · 1 người được giao ·
-
docs(mdbook-htmx): Parent Issue for documentationCó thể làm lại được @aRustyDev đã nhận 287 ngày trước và không có pull request nào đang mở. Đang mởdocumentation
aRustyDev/mdbook-htmx#47 · 1 người được giao ·
-
docs(examples): Secure Self-Hosted Meilisearch via CloudflareCó thể làm lại được @aRustyDev đã nhận 287 ngày trước và không có pull request nào đang mở. Đang mởdocumentation
aRustyDev/mdbook-htmx#46 · 1 người được giao ·
-
docs(examples): Kubernetes with MeilisearchCó thể làm lại được @aRustyDev đã nhận 287 ngày trước và không có pull request nào đang mở. Đang mởdocumentation
aRustyDev/mdbook-htmx#45 · 1 người được giao ·
Tất cả issue của aRustyDev/mdbook-htmx
Issue tương tự
-
engine-rs P3 review-deferral wasm
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 77/100
maniator/verticopolis#1154 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
FFMPEG_BIN/FFPROBE_BIN are always overridden, so a working system ffmpeg cannot be usedCó thể đã có người làm @Bilker1422 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Stremio/stremio-service#116 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
sims1253/ry#720 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày