Skip to content

Ship type declarations for @webjsdev/server (fix TS7016 on import) #310

Description

@vivek7405

Problem

@webjsdev/core ships an index.d.ts overlay, but @webjsdev/server ships no .d.ts and no types export condition in its package.json. So under strict + nodenext, a TypeScript app's import { createRequestHandler, cors, cache, createAuth, rateLimit, sitemap, validateInput, revalidatePath, ... } from '@webjsdev/server' emits TS7016 ("Could not find a declaration file for module '@webjsdev/server'").

This was surfaced while building #265 (the webjs typecheck command) and #267 (the handle() test harness): it is exactly why #265 deliberately did NOT wire npm run typecheck into the scaffold CI as a hard gate, because a fresh scaffold would fail it on the server import. It also means the Next.js migration guide (#273) and the recipes (#272) show @webjsdev/server imports that are currently untyped, and every TS webjs app gets any/an error for a first-party module the docs push as the API.

Design / approach

Add a types-only overlay for the public @webjsdev/server surface, the same posture @webjsdev/core uses (index.d.ts re-exporting from per-file .d.ts, erased at runtime, zero build cost). Type what packages/server/index.js actually exports, matching the runtime, never an idealized superset. Candidates: createRequestHandler / startServer, cors, cache / revalidateTag / revalidatePath / revalidateAll, createAuth / Credentials / Session, rateLimit, setStore / redisStore / memoryStore, sitemap / sitemapIndex, generateRouteTypes, the @webjsdev/server/testing helpers, and the @webjsdev/server/check subpath. Add a types condition to each exports subpath in package.json so editors and tsc resolve it. Keep it in lockstep with index.js (a drift guard test, like the #259 WebjsConfig schema/type lockstep).

Acceptance criteria

  • @webjsdev/server ships a types overlay so a strict TS app's import ... from '@webjsdev/server' no longer emits TS7016
  • The package.json exports carry a types condition for the main entry and each subpath (/testing, /check)
  • The typed surface matches what index.js actually exports (a drift test asserts no missing/extra export), never a superset
  • Once shipped, npm run typecheck can be wired into the scaffold CI without failing on the server import (revisit Add a webjs typecheck command (tsc --noEmit wrapper) #265's deferred CI gate)
  • Tests cover the new behaviour (a tsc --noEmit fixture importing the server surface compiles clean)
  • Docs / AGENTS.md updated if the public surface changed

Surfaced from the production-readiness work (#265 typecheck, #267 test harness). Theme: types. Priority: P1. Kept to webjs identity: no-build, types-only overlay, erased at runtime.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions