AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

TypedRoutes Invalid Link Href Not Enforced By Tsc In Workspace App Unless .Next/Types/Link.D.Ts Is Manually Referenced

In a monorepo/workspace setup, next typegen generates .next/types/routes.d.ts and .next/types/link.d.ts, but the generated next-env.d.ts only imports routes.d.ts. As a result, TypeScript does not automatically load the module augmentations for next/link and next/navigation, so invalid Link href values are not caught by tsc --build or tsc --noEmit. This violates the expected behavior documented for next typegen.

highConfidence 90%Next.jsnext buildReact Server ComponentsAffected V16.2.4

Origin Analysis

Next.js's type generation (next typegen) creates separate declaration files (routes.d.ts and link.d.ts) under .next/types, but the generated next-env.d.ts only imports routes.d.ts and omits an import for link.d.ts. In a standalone project, TypeScript may pick up link.d.ts via default include patterns, but in a workspace with a custom tsconfig include (e.g., only src/**, next-env.d.ts), the .next/types directory is not part of the compilation, so the link.d.ts module augmentations are never loaded. The manual reference of link.d.ts works because it forces TypeScript to include that file.
1. Clone repo https://github.com/jakeleventhal/next-typed-routes-workspace-tsc-repro 2. Run `bun install` 3. Run `bun run -F @repro/web typegen` 4. Confirm `.next/types/routes.d.ts` and `.next/types/link.d.ts` exist and `next-env.d.ts` only imports routes.d.ts 5. Run `bun run -F @repro/web tsc` or `bun run -F @repro/web tsc:noemit` → succeeds 6. Run `bun run -F @repro/web tsc:with-link-augmentation` (which explicitly loads link.d.ts) → fails with TS2322 error

Fixing Code Block

Edge Case Audit

This fix requires that `.next/types` files exist before running `tsc`. If `next typegen` has not been executed, TypeScript will fail to find the included files and may throw errors. It is recommended to always run `next typegen` before type checking (e.g., `next typegen && tsc --noEmit`). Additionally, the include pattern may break if Next.js changes the output structure of `.next/types` in future versions. Rollback is straightforward: remove the `.next/types/**/*.ts` and `.next/types/**/*.d.ts` entries from the `include` array. In a monorepo, ensure each app has its own `.next/types` path correctly included to avoid cross-project contamination.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state