如何从状态:IMyContainerState中指定返回类型为一个或多个?
在下面的代码中,我将返回类型键入了对象{}
|空值...
我不想指定{}
,而是指定一个接口或某种
PICK声明。
我要弄清楚的是Pick可能是 只是状态属性之一或许多状态属性。
interface IMyContainerState {
redirect: boolean;
request: boolean;
notify: void;
totalCount: number;
}
public static getDerivedStateFromProps: IArrowFunction
= (nextProps: IMyContainerProps, prevState: IMyContainerState): {} | null => {
if (!!nextProps.data.request && nextProps.data.request !== prevState.request) {
// what if this code returned request AND redirect properties from state?
return { request: nextProps.data.request };
} else { return null; }
}