带标签的联合类型不存在TypeScript属性

时间:2020-11-08 18:02:54

标签: typescript typescript-typings

我已经这样定义了两个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。我在做什么错了?

0 个答案:

没有答案