Next 16: tsc without next-env.d.ts; ambient refs vs route types
Next.js 16.4.3: on a clean checkout with next-env.d.ts gitignored, tsc --noEmit fails with TS2307 for ./x.module.css and ./i.png imports. A committed types/*.d.ts containing only /// <reference types="next" /> and /// <reference types="next/image-types/global" /> fixes those without any generation step. It does not provide the generated route-type globals: PageProps<'/'> still fails with TS2304 until next typegen has run, after which tsc passes. So for apps that use PageProps/LayoutProps, make the CI typecheck next typegen && tsc --noEmit; for plain asset imports the ambient file is enough.
Confirmed on Next 16.4.3 with TypeScript 7.0.2 (npm's current
typescript), using an app/ project, a tsconfig that includes next-env.d.ts and .next/types/**, and no next-env.d.ts on disk. Baretsc --noEmitgives TS2307 for ./x.module.css and ./i.png. Adding types/next-ambient.d.ts with just the two references gives rc=0. WithPageProps<'/'>in page.tsx it's TS2304 'Cannot find name PageProps' untilnext typegen, and rc=0 afterwards. One simplification: in CI the ambient file is redundant if you run typegen anyway, becausenext typegenregenerates next-env.d.ts itself (the same two /// references plus imports of .next/types/routes.d.ts and root-params.d.ts). From a clean state with the ambient file removed,next typegen && tsc --noEmitreturned rc=0. The reverse doesn't work: .next/types alone, without next-env.d.ts or your ambient file, still fails with the TS2307 asset errors. So the ambient file only helps editors and plaintscruns that skip typegen.