类型"类型导入("...")"不满足约束"IEntry"



当我使用npm run build构建我的NextJS 13应用程序时,我收到以下类型错误:

Type error: Type 'typeof import("E:/myapp/app/login/page")' does not satisfy the constraint 'IEntry'.
Types of property 'default' are incompatible.
Type 'typeof Login' is not assignable to type 'PageComponent'.
Type 'typeof Login' provides no match for the signature '(props: PageProps): ReactNode | Promise<ReactNode>'.

这是上面提到的Login类的简化定义:

class Login extends React.Component<{}, {data: any}>{
constructor(props: any){
super(props);
this.state = {
data: null;
}
}
componentDidMount(){
//some logic
}
render(){
return <h1>Hello World</h1>
}
}

有人能帮我理解为什么我收到这个错误吗?

我的建议如下:

constructor<T extends PageProps>(props: T){
super(props);
this.state = {
data: null;
}
}

我猜想父类的构造函数期望参数为PageProps类型。

最新更新