Next.js:Type 'OmitWithTag<{ }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.
![Next.js:Type 'OmitWithTag<{ }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.](https://static.blogweb.cn/article/bdd3680860324810b66e5193c82af2de.webp)
Type error: Type 'OmitWithTag<{ data: any[]; }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'. Property 'data' is incompatible with index signature. Type 'any[]' is not assignable to type 'never'.
在使用Next.js的app router开发时有时会出现类似这样的报错,这种情况主要出现在pages router向app router迁移时,主要因为:
![Next.js:Type 'OmitWithTag<{ }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.](https://static.blogweb.cn/article/45137ed9d428466daa14a0fe4af2c380.webp)
这样,开发者修改了路由函数组件的入参类型,我们在编写page.tsx文件时不要使用NextPage或者FC类型修改props参数(也没有props参数,只有Context参数),只要将他删除就好了。对app文件夹下的page文件全部检查一遍即可。这样就正常了。
![Next.js:Type 'OmitWithTag<{ }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.](https://static.blogweb.cn/article/fb873c3f43954a6ca9305bbb588ae026.webp)
当然还有一种情况:
![Next.js:Type 'OmitWithTag<{ }, keyof PageProps, "default">' does not satisfy the constraint '{ [x: string]: never; }'.](https://static.blogweb.cn/article/d1bcecaa2ef3483bb20b621720961b9b.webp)
原因为page.tsx文件除了组件不要导出其他的东西,type类型除外。将export导出的东西单独存放在app文件外的文件中,然后引入就好了。
export const a={}//删掉,封装好,单独引入