I have a react component PageLayout written in typescript:
export interface IPageLayoutProps {...}
export interface IPageLayoutActions {...}
export interface IPageLayoutLocalState {...}
export default
class PageLayout<P extends IPageLayoutProps & IPageLayoutActions, S extends Object>
extends React.Component<P, S>
{
render() {
return (...)
}
}
and then I try to extend this component like this:
import PageLayout, { IPageLayoutProps, IPageLayoutActions, IPageLayoutLocalState } from './PageLayout'
export interface IPageLayoutSidebarProps {...}
export interface IPageLayoutSidebarActions {...}
interface IPageLayoutSidebarState {sidebarVisible: boolean}
export default
class PageLayoutSidebar<P extends IPageLayoutSidebarProps & IPageLayoutSidebarActions & IPageLayoutProps & IPageLayoutActions, S extends IPageLayoutSidebarState & IPageLayoutLocalState>
extends PageLayout<P, S>
{
render() {
return (...)
}
toggleSidebar(visible:boolean) {
this.setState({
...this.state,
sidebarVisible: visible
})
}
}
the problem is that I'm getting error when trying to call this.setState, it tell me that "spread types may only be created from object types". Anyone has any idea what could be wrong with state and why I can't use spread operator on it?