我已经这样定义了两个interface
:
interface SignInCleanResponse {
type: string;
payload: {
action: string;
}
}
interface SignInError {
type: string;
}
现在有一个type
:
type Action = SignInCleanResponse | SignInError;
然后在我的代码中,我有:
export default function auth (state = defaultState, action: Action) {
return action.payload // Error
}
错误是:
TS2339: Property 'payload' does not exist on type 'Action'. Property 'payload' does not exist on type 'SignInError'
我期望带有标记联合的Action
是SignInCleanResponse或SignInError的接口,而SignInCleanResponse具有payload.action
。我在做什么错了?