在使用新的Next.js 13实验路由API创建GET处理程序时,我试图不使用any
类型。
export async function GET(request: any, {params}: any) {
function getRandomInt(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min) + min); // The maximum is exclusive and the minimum is inclusive
}
const youTubeId = params.id;
我试过HttpWebResponse
,但是没有用。
export async function GET(request: Request) {
return new Response('Hello world')
}
Request
和Response
是全局可用的。它的类型将被推断为function GET(request: Request): Promise<Response>
或者可以使用NextResponse
import { NextResponse } from "next/server";
export async function GET(request: Request) {
return NextResponse.json({ message:"success" }, { status: 200 });
}
及其类型将被推断为function GET(request: Request): Promise<NextResponse>