Skip to content

Commit 7c02a45

Browse files
os-zhuangclaude
andauthored
fix(docs): type-check the docs app with next typegen, and delete the dead types:check (#10879)
`apps/docs` declared two near-identical type-check scripts: "types:check": "fumadocs-mdx && next typegen && tsc --noEmit" "typecheck": "tsc --noEmit" `types:check` -- the thorough one -- was invoked by nothing (`git grep` over `.github/`, `scripts/`, `turbo.json` and the root `package.json` returns only its own declaration). The one CI actually runs is `typecheck`, reached through `turbo run typecheck --filter='./apps/*'`. That mattered because `tsconfig.json` includes `.next/types/**/*.ts`, which only `next typegen` produces. So the program CI type-checked was set by whether some earlier, unrelated command had populated `.next` -- and on a fresh checkout it had not. Measured with `.next` deleted, the bare script exits 0 while compiling none of the generated route types. Wiring the thorough command under the name CI already runs makes the check a function of source: it generates `.next/types/**` and `next-env.d.ts` itself before tsc reads them, and short-circuits loudly if typegen fails. Typegen costs ~1s and needs no build. Measured coverage delta (empty `.next`, `tsc --listFiles`): 1225 -> 1231 files. The six are `.next/types/validator.ts` (160 lines validating 13 route entry points), `routes.d.ts`, `root-params.d.ts`, `cache-life.d.ts`, `next-env.d.ts` and, through it, `next/image-types/global.d.ts` -- so the bare run was also type-checking a Next app without Next's own ambient declarations. Ablation, to show the added coverage is real: giving `app/[lang]/docs/layout.tsx` a `params` shape the route cannot supply leaves the old script green (exit 0, 0 errors) and makes the new one fail with TS2344 at `.next/types/validator.ts`, naming the layout and the missing param. `include` is deliberately left alone. Next writes both `.next` globs itself and re-adds either one on the next `next dev` / `next build`; running `writeConfigurationDefaults` against a narrowed copy put the `dev` glob straight back and rewrote the file. The rationale is recorded in `tsconfig.json` where the next reader would try to tidy it. Claude-Session: https://claude.ai/code/session_01DdCnBGcHeufjrq7drTD3wt Co-authored-by: Claude <noreply@anthropic.com>
1 parent 3854376 commit 7c02a45

2 files changed

Lines changed: 25 additions & 2 deletions

File tree

‎apps/docs/package.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
99
"build": "pnpm --filter @objectstack/spec gen:schema && pnpm --filter @objectstack/spec gen:docs && NODE_OPTIONS='--max-old-space-size=4096' next build",
1010
"start": "next start",
1111
"site:lint": "next lint",
12-
"types:check": "fumadocs-mdx && next typegen && tsc --noEmit",
1312
"postinstall": "fumadocs-mdx",
14-
"typecheck": "tsc --noEmit"
13+
"typecheck": "fumadocs-mdx && next typegen && tsc --noEmit"
1514
},
1615
"dependencies": {
1716
"fumadocs-core": "16.14.4",

‎apps/docs/tsconfig.json‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,30 @@
3434
]
3535
}
3636
},
37+
// `typecheck` runs `next typegen` before tsc on purpose, and these two
38+
// `.next` globs are why. Next writes both of them itself
39+
// (`writeConfigurationDefaults`) and re-adds either one on the next
40+
// `next dev` / `next build` if you delete it -- measured by running that
41+
// routine against a narrowed copy of this file: the `dev` glob came
42+
// straight back and the file was rewritten. This array cannot be narrowed,
43+
// so the honesty has to come from the script instead.
44+
//
45+
// .next/types/** produced by the `next typegen` that the `typecheck`
46+
// script now runs itself, so the checked program is a
47+
// function of source rather than of whatever `.next` an
48+
// earlier build happened to leave behind. A bare
49+
// `tsc --noEmit` here passed over a broken route
50+
// signature precisely because these files were absent.
51+
// .next/dev/types/** written only by `next dev`. Next's own build-mode
52+
// type check filters this directory OUT of the program
53+
// (`getDevTypesPath`, lib/typescript/runTypeCheck.js)
54+
// "to prevent stale dev types from causing errors when
55+
// routes have been deleted since the last dev session".
56+
// Plain tsc has no such filter, so a leftover dev
57+
// session can only add a local false RED here, never a
58+
// false green. Remedy: `rm -rf apps/docs/.next`.
59+
//
60+
// Do not reduce `typecheck` back to a bare `tsc --noEmit`.
3761
"include": [
3862
"next-env.d.ts",
3963
"**/*.ts",

0 commit comments

Comments
 (0)