diff --git a/packages/next/src/server/lib/router-utils/typegen.ts b/packages/next/src/server/lib/router-utils/typegen.ts index 75bdf7038eeb78..6677d309e414d4 100644 --- a/packages/next/src/server/lib/router-utils/typegen.ts +++ b/packages/next/src/server/lib/router-utils/typegen.ts @@ -446,10 +446,13 @@ export function generateValidatorFile( : type return `// Validate ${filePath} { + type __IsExpected = Specific const handler = {} as typeof import(${JSON.stringify( importPath.replace(/\.tsx?$/, '.js') )}) - handler satisfies ${typeWithRoute} + type __Check = __IsExpected + // @ts-ignore + type __Unused = __Check }` }) .join('\n\n') diff --git a/test/e2e/app-dir/typed-routes-validator/typed-routes-validator.test.ts b/test/e2e/app-dir/typed-routes-validator/typed-routes-validator.test.ts index 0967ebe2d11f9b..01a00d8f032c2e 100644 --- a/test/e2e/app-dir/typed-routes-validator/typed-routes-validator.test.ts +++ b/test/e2e/app-dir/typed-routes-validator/typed-routes-validator.test.ts @@ -13,7 +13,7 @@ describe('typed-routes-validator', () => { it('should generate route validation correctly', async () => { const dts = await next.readFile('.next/types/validator.ts') // sanity check that dev generation is working - expect(dts).toContain('handler satisfies AppPageConfig') + expect(dts).toContain('const handler = {} as typeof import(') }) if (isNextStart) { @@ -51,7 +51,7 @@ describe('typed-routes-validator', () => { expect(exitCode).toBe(1) expect(cliOutput).toMatch( - /Type error: Type 'typeof import\(.*\)' does not satisfy the expected type 'AppPageConfig<"\/invalid">'/ + /Type error: Type 'typeof import\(.*' does not satisfy the constraint 'AppPageConfig { expect(exitCode).toBe(1) expect(cliOutput).toMatch( - /Type error: Type 'typeof import.*does not satisfy the expected type 'RouteHandlerConfig<"\/invalid">'/ + /Type error: Type 'typeof import\(.*' does not satisfy the constraint 'RouteHandlerConfig { await next.deleteFile('app/invalid-2/route.ts') expect(exitCode).toBe(1) - expect(cliOutput).toContain(`Types of property 'POST' are incompatible.`) + expect(cliOutput).toMatch( + /Type error: Type 'typeof import\(.*' does not satisfy the constraint 'RouteHandlerConfig { @@ -174,7 +176,7 @@ describe('typed-routes-validator', () => { expect(exitCode).toBe(1) expect(cliOutput).toMatch( - /Type error: Type 'typeof import\(.*does not satisfy the expected type 'LayoutConfig<"\/invalid">'/ + /Type error: Type 'typeof import\(.*' does not satisfy the constraint 'LayoutConfig { expect(exitCode).toBe(1) expect(cliOutput).toMatch( - /Type error: Type 'typeof import\(.*does not satisfy the expected type 'ApiRouteConfig'/ + /Type error: Type 'typeof import\(.*' does not satisfy the constraint 'ApiRouteConfig'/ ) }) }