Javascript 从TypeScript中的状态分解值时出错

Javascript 从TypeScript中的状态分解值时出错,javascript,reactjs,typescript,Javascript,Reactjs,Typescript,当我试图对通知菜单值进行解构时,我收到了错误信息 像这样 我正在使用Redux进行状态管理 import React,{suspent,Component}来自'React'; 从“react router dom”导入{Switch,Route}; 从'react redux'导入{connect}; 从“/Redux/NotificationMenu/nof_选择器”导入{NotificationMenu}”; 类应用程序扩展组件{ 状态={ navOpen:错, }; 导航呼叫=()=>

当我试图对通知菜单值进行解构时,我收到了错误信息 像这样

我正在使用Redux进行状态管理

import React,{suspent,Component}来自'React';
从“react router dom”导入{Switch,Route};
从'react redux'导入{connect};
从“/Redux/NotificationMenu/nof_选择器”导入{NotificationMenu}”;
类应用程序扩展组件{
状态={
navOpen:错,
};
导航呼叫=()=>{
this.setState({navOpen:!this.state.navOpen});
};
render(){
console.log(这个.props.notification_菜单);
const{navOpen}=this.state;
const NavOpenStyleMargin=navOpen?{marginLeft:“250px”}:{};
返回(
)
}
}
常量mapStateToProps=(状态:任意)=>{
返回{
//userID:selectCurrentUser(状态),
//账户菜单:账户菜单(状态),
通知菜单:通知菜单(状态),
};
};
导出默认连接(MapStateTops,null)(应用程序);

使用typescript时,需要向类组件声明道具和状态类型,如:

interface IProps {
  notification_menu: string // define what type notification_menu is
}

interface IState {
  navOpen: boolean
}

class MyComponent extends React.Component<IProps, IState> {
  // code here
}
接口IProps{
通知菜单:字符串//定义通知菜单的类型
}
界面状态{
navOpen:布尔值
}
类MyComponent扩展了React.Component{
//代码在这里
}

考虑避免
any
以使错误更加明确-
any
有点违背使用TS的目的
interface IProps {
  notification_menu: string // define what type notification_menu is
}

interface IState {
  navOpen: boolean
}

class MyComponent extends React.Component<IProps, IState> {
  // code here
}