Javascript 财产';profileStore';类型'中缺少;{}';但类型为';只读<;AppProps>';。ts(2741)
我正在使用mobx反应类型脚本 为什么Javascript 财产';profileStore';类型'中缺少;{}';但类型为';只读<;AppProps>';。ts(2741),javascript,reactjs,typescript,mobx-react,Javascript,Reactjs,Typescript,Mobx React,我正在使用mobx反应类型脚本 为什么显示错误 我只需要设置默认道具吗 属性“profileStore”在类型“{}”中丢失,但在类型“Readonly”中是必需的。ts(2741) tsx(9,3):“profileStore”在这里声明。 (别名)类主注释 导入主注释 我不想传递道具,因为它是由mobx弹出的道具 谢谢你的帮助 代码如下 import React,{Component}来自'React'; 从“/MainNote”导入MainNote; 从'mobx'导入{可观察,
显示错误
我只需要设置默认道具吗
属性“profileStore”在类型“{}”中丢失,但在类型“Readonly”中是必需的。ts(2741)
tsx(9,3):“profileStore”在这里声明。
(别名)类主注释
导入主注释
我不想传递道具,因为它是由mobx弹出的道具
谢谢你的帮助
代码如下
import React,{Component}来自'React';
从“/MainNote”导入MainNote;
从'mobx'导入{可观察,计算}
从“mobx react”导入{observer,inject,IStoresToProps}
从“../interfaces/store/IStore”导入{IStore}
从“../styles/App.module.css”导入样式;
从“../interfaces/Profile/IProfileStore”导入{IProfileStore};
从“../interfaces/Profile/iProfile”导入{iProfile};
接口AppProps{
profileStore?:IProfileStore
}
导出接口IProfileStore{
个人资料:iProfile,
柜台号码:,
loadProfile?:()=>void
}
@注入(“profileStore”)
@观察者
类应用程序扩展组件{
静态defaultProps={profileStore:{counter:0}};
render(){
返回(
{console.log('props',this.props.profileStore)}
);
}
}
导出默认应用程序代码>答案是在组件中设置默认道具
static defaultProps = {profileStore:{}}
从以下位置将profileStore道具设置为必需:
interface AppProps {
profileStore: IProfileStore;
}
任选
interface AppProps {
profileStore?: IProfileStore;
}
对于看到相同错误的其他人
当您将与Styles一起使用时,同样的问题也会发生,并且您将该类导入到大括号中,如下所示:
import{mainpote}来自“/mainpote”;
这将直接导入类本身而不应用样式,因此它缺少类
。只需删除大括号即可导入默认导出:
从“/mainpote”导入mainpote;
档案库?:IProfileStore代码>在main注释中
interface AppProps {
profileStore?: IProfileStore;
}