mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
### What #51394 introduced a pretty strict type of return value of route type that causing failure with `next build`. There're few ways of writing a app route, it could contain few return values based on the usage: * return a `Response` or promise of it * return `NextResponse` of promise of it, since it's extended from `Response`, same type * use `redirect()` or `notFound(), since it returns `never`, and the below code is not reached, the handler itself could still return void. e.g. using `redirect` in a `GET` route We loosed the type so `redirect()` can be still allowed without specifying the return value there. Related typescript issue: https://github.com/microsoft/TypeScript/issues/16608#issuecomment-309327984 ### How * Re-enable the bail on types / build error in the app-routes tests * Separate the tests, move runtime erroring ones to `test/e2e/app-dir/app-routes-errors` * Add new case to app-routes tests of mixed return value Closes #55623 Related #55604
13 lines
296 B
TypeScript
13 lines
296 B
TypeScript
import { redirect } from 'next/navigation'
|
|
import { NextResponse } from 'next/server'
|
|
|
|
export async function GET() {
|
|
if (process.env.COND_1) {
|
|
return NextResponse.json({ a: '1' })
|
|
} else if (process.env.COND_2) {
|
|
redirect('/no-response')
|
|
} else {
|
|
return new Response('3')
|
|
}
|
|
}
|