feat: type guard file generation (#81400)
## Overview
Generates `.next/types/validator.ts` - a single TypeScript file that
validates all route exports using the `satisfies` operator. Replaces the
old `next-types-plugin` webpack plugin.
## Why needed
- **Turbopack compatibility**: Old webpack plugin didn't work with
Turbopack
- **Performance**: Single large file vs hundreds of small validation
files
- **Type safety**: Catches invalid exports like `dynamic =
'invalid-value'`
## Validation Structure
```typescript
// Type definitions
type PageConfig = {
default: React.ComponentType<any>
config?: {}
generateMetadata?: (props: any, parent: any) => Promise<any> | any
dynamic?: 'auto' | 'force-dynamic' | 'error' | 'force-static'
// ... other Next.js exports
}
// Validation checks
// Validate app/page.tsx
{
const handler = {} as typeof import("../../app/page")
handler satisfies PageConfig
}
...
```
## Example Usage
```typescript
// app/blog/[slug]/page.tsx
export const dynamic = 'some-random-string' // ← Type error caught!
export default async function BlogPostPage(props: PageProps<'/blog/[slug]'>) {
const params = await props.params
return <div>Blog Post: {params.slug}</div>
}
```
## Key Benefits
- **Build-time validation**: Catches invalid route exports during
TypeScript compilation
- **Turbopack support**: Works with both webpack and Turbopack
- **Better performance**: One file instead of hundreds of small type
guard files
Showing
Please
register
or
sign in
to comment