我刚刚使用应用程序路由器方法从 NextJS 14 迁移到 15。在 Windows 上。
我的其中一个静态路由有问题。它不是动态路线,但会出现错误,就好像它是动态路线一样。
interface Context {
data: object;
params: any;
}
export async function POST(request: NextRequest, context: Context) {
const testBody = await request.json();
....function continues on....
......
当我运行:
npm run dev
时,它工作正常,但是当我使用:npm run build
构建时,它无法通过linting and checking validity of types
。我收到以下错误:
PS C:\Users\SJ\Desktop\nextjsProject> npm run build
> build
> next build
▲ Next.js 15.0.3
- Environments: .env
Creating an optimized production build ...
✓ Compiled successfully
Linting and checking validity of types ..Failed to compile.
.next/types/app/api/myRoute/route.ts:166:7
Type error: Type '{ __tag__: "POST"; __param_position__: "second"; __param_type__: Context; }' does not satisfy the constraint 'ParamCheck<RouteContext>'.
Types of property '__param_type__' are incompatible.
Property 'params' is missing in type 'Context' but required in type 'RouteContext'.
164 | Diff<
165 | ParamCheck<aRouteContext>,
> 166 | {
| ^
167 | __tag__: 'POST'
168 | __param_position__: 'second'
169 | __param_type__: SecondArg<MaybeField<TEntry, 'POST'>>
Interface Context
参数更改为 Promise<string>
和 Promise<any>
Interface Context
更改为 type Context
context : Context
我传入 context: {params: Promise<any>}
请帮忙!
将
context: Context
替换为 { params }: { params: Promise<{ id: string }> }
然后,使用以下命令检索值:
const id = (await params).id