Unverified Commit fddaeb85 authored by Ben Gubler's avatar Ben Gubler Committed by GitHub

[backport] fix: remove `satisfies` keyword from type validation to preserve old…

[backport] fix: remove `satisfies` keyword from type validation to preserve old TS compatibility (#83071)
parent 497ec6aa
...@@ -446,10 +446,13 @@ export function generateValidatorFile( ...@@ -446,10 +446,13 @@ export function generateValidatorFile(
: type : type
return `// Validate ${filePath} return `// Validate ${filePath}
{ {
type __IsExpected<Specific extends ${typeWithRoute}> = Specific
const handler = {} as typeof import(${JSON.stringify( const handler = {} as typeof import(${JSON.stringify(
importPath.replace(/\.tsx?$/, '.js') importPath.replace(/\.tsx?$/, '.js')
)}) )})
handler satisfies ${typeWithRoute} type __Check = __IsExpected<typeof handler>
// @ts-ignore
type __Unused = __Check
}` }`
}) })
.join('\n\n') .join('\n\n')
......
...@@ -13,7 +13,7 @@ describe('typed-routes-validator', () => { ...@@ -13,7 +13,7 @@ describe('typed-routes-validator', () => {
it('should generate route validation correctly', async () => { it('should generate route validation correctly', async () => {
const dts = await next.readFile('.next/types/validator.ts') const dts = await next.readFile('.next/types/validator.ts')
// sanity check that dev generation is working // sanity check that dev generation is working
expect(dts).toContain('handler satisfies AppPageConfig') expect(dts).toContain('const handler = {} as typeof import(')
}) })
if (isNextStart) { if (isNextStart) {
...@@ -51,7 +51,7 @@ describe('typed-routes-validator', () => { ...@@ -51,7 +51,7 @@ describe('typed-routes-validator', () => {
expect(exitCode).toBe(1) expect(exitCode).toBe(1)
expect(cliOutput).toMatch( 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</
) )
}) })
...@@ -111,7 +111,7 @@ describe('typed-routes-validator', () => { ...@@ -111,7 +111,7 @@ describe('typed-routes-validator', () => {
expect(exitCode).toBe(1) expect(exitCode).toBe(1)
expect(cliOutput).toMatch( 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</
) )
}) })
...@@ -132,7 +132,9 @@ describe('typed-routes-validator', () => { ...@@ -132,7 +132,9 @@ describe('typed-routes-validator', () => {
await next.deleteFile('app/invalid-2/route.ts') await next.deleteFile('app/invalid-2/route.ts')
expect(exitCode).toBe(1) 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</
)
}) })
it('should pass type checking with valid layout exports', async () => { it('should pass type checking with valid layout exports', async () => {
...@@ -174,7 +176,7 @@ describe('typed-routes-validator', () => { ...@@ -174,7 +176,7 @@ describe('typed-routes-validator', () => {
expect(exitCode).toBe(1) expect(exitCode).toBe(1)
expect(cliOutput).toMatch( 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</
) )
}) })
...@@ -220,7 +222,7 @@ describe('typed-routes-validator', () => { ...@@ -220,7 +222,7 @@ describe('typed-routes-validator', () => {
expect(exitCode).toBe(1) expect(exitCode).toBe(1)
expect(cliOutput).toMatch( 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'/
) )
}) })
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment