2026-03-18 TypeScript Adoption Plan β
Goal β
Adopt TypeScript incrementally across Lantern to improve safety at app/service boundaries, reduce runtime regressions, and keep delivery velocity high.
Current State (Verified) β
- No active TypeScript source files (
.ts,.tsx,.mts,.cts) found. - No
tsconfig*.jsoncurrently present. - Tooling is partially TS-ready:
- Vitest includes TS/TSX patterns in web/admin test globs.
- Storybook story globs include
ts|tsx. - Header validation scripts already account for
ts|tsx.
- Main implementation remains JS/JSX (
apps/web,apps/admin,services/*,packages/*).
Recommendation β
Proceed with a phased migration (hybrid JS + TS), not a big-bang rewrite.
Why:
- Low tooling friction (some TS-ready config already exists).
- High payoff in shared contracts and backend/API boundaries.
- Minimal disruption if introduced in layers.
Scope β
In scope:
- Add TypeScript compiler + baseline config.
- Enable type-checking in CI.
- Introduce typed shared contracts first.
- Migrate high-risk/high-churn modules incrementally.
Out of scope (initially):
- Full repo conversion in one pass.
- Strict mode everywhere on day one.
- Rewriting stable/low-risk modules just for extension parity.
Phased Rollout β
Phase 0: Baseline Setup (1 PR) β
Deliverables:
- Add
typescriptand essential type packages. - Add root
tsconfig.base.json. - Add workspace tsconfigs for web/admin/services/packages as needed.
- Keep JS running via
allowJs: true. - Enable checks with
checkJs: truewhere valuable. - Add
typecheckscripts and wire into validation.
Success criteria:
typecheckruns in CI without changing runtime behavior.- Existing build/test/lint pipelines remain green.
Phase 1: Shared Contracts First (1β2 PRs) β
Targets:
packages/shared(constants, service registry contracts, rate limit schema).- Introduce explicit interfaces/types for:
- API services registry entries.
- CORS origin sets.
- Rate limit presets.
Success criteria:
- Shared package exports typed contracts consumed by apps/services.
- No regressions in imports or runtime execution.
Phase 2: Backend/API Boundary Hardening (2β4 PRs) β
Targets:
- Cloud Run services with HTTP payload boundaries first:
services/api/authservices/api/analyticsservices/api/venuesservices/api/lanterns
Focus:
- Request/response DTO typing.
- Auth/session payload typing.
- Firestore document shape typing at read/write boundaries.
- Runtime validation preserved (types do not replace validation).
Success criteria:
- Boundary modules typed.
- Reduced βshape mismatchβ bugs in integration tests.
Phase 3: Frontend High-Value Modules (2β4 PRs) β
Targets:
apps/web/src/lib/*service modules first.- Shared component props in frequently reused UI primitives.
- State and event payload typing where bugs have historically occurred.
Success criteria:
- Core service modules typed.
- Component prop contracts documented by TS.
- No drop in test coverage threshold compliance.
Phase 4: Tighten Rules (optional) β
- Incrementally enable stricter compiler flags by folder/package.
- Convert remaining opportunistically touched files.
- Keep mixed JS/TS support until migration ROI declines.
Proposed Compiler Strategy β
Initial defaults:
allowJs: truecheckJs: true(can be selective)noEmit: true(build still via existing Vite/toolchain)skipLibCheck: truestrict: falseinitially, then ratchet up package-by-package
Ratcheting sequence:
noImplicitAnystrictNullChecks- broader
strict
CI & Quality Gates β
Add/adjust:
typecheckcommand per workspace.- Root validation pipeline includes typecheck.
- Keep existing lint/tests/coverage unchanged during rollout.
Guardrails:
- No deployment/process changes.
- No branch strategy changes.
- Avoid coupling migration PRs with feature PRs.
Risks & Mitigations β
Risk: migration churn slows feature delivery
Mitigation: small PRs, boundary-first prioritization, mixed JS/TS period
Risk: false confidence from types alone
Mitigation: keep runtime validation for external inputs
Risk: CI noise from strictness too early
Mitigation: start permissive, ratchet strictness gradually
Suggested First Conversion Targets β
- Shared service registry and related config contracts (
packages/shared/services). - API boundary handlers in
services/api/auth. - Shared utility modules with repeated cross-project usage.
Definition of Done (Initial Adoption) β
- TypeScript installed and configured at workspace level.
- Typecheck runs in CI and passes.
packages/sharedexports typed contracts used by at least one app and one service.- At least one backend service has typed request/response boundaries.
- No runtime or deployment regressions.
Execution Notes β
- Keep PRs focused and reversible.
- Prefer converting touched files over mass rename sweeps.
- Document migration decisions in the PR body and changelog after completion.