I have the following interface:
export interface withAuthState {
ready: boolean,
session: any
}
And the following HOC:
const withAuth = <P extends withAuthProps, S extends withAuthState>(
WrappedComponent: new (props: P) => RX.Component<P, S>
) => class WithAuth extends RX.Component<P & withAuthProps, S & withAuthState> {
constructor(props) {
super(props);
this.state = {
ready: false,
session: null
};
}
}
I'm unable to set the state in the constructor. The error is:
TS2322: Type '{ ready: false; session: null; }' is not assignable to type 'Readonly<S & withAuthState>'.
I'm clearly missing something here, but I do not know what.
Any help appreciated. Thanks in advance.
` This will not compile without `P` and `S`. Where are these defined ? could you post your full code ?
– Titian Cernicova-Dragomir Mar 14 '18 at 08:44