问问题
331 次
1 回答
0
问题是状态可能有其他属性,您无法初始化这些属性,因为您在 HOC 中不知道它们。考虑以下:
class MyComponent extends RX.Component<withAuthProps, withAuthState & { myStateProp: number }>{}
const MyComponentWithAuth = withAuth(MyComponent);
let comp = new MyComponentWithAuth({});
// myStateProp does not exist on state because you did not initialize it in your HOC even though the property is required
comp.state.myStateProp
如果你对这种行为没问题,你可以在初始化状态时使用类型断言:
this.state = {
ready: false,
session: null
} as S & withAuthState;
于 2018-03-14T09:05:37.703 回答