将接口并集导出为类型抛出错误

时间:2019-07-24 08:06:57

标签: typescript

我正在使用Typescript编写基于react / redux的应用程序。我想对动作接口进行专家联合,以便可以在reducer中用作ActionType。但是编译器抛出错误,找不到这样的导出。

// Filename: store/app/app.actions
import {
  Language,
  LANGUAGE_SELECTED,
  User,
  USER_FOUND
} from './app.types';

interface UserFoundAction {
  type: typeof USER_FOUND;
  payload: User
}

interface LanguageSelectedAction {
  type: typeof LANGUAGE_SELECTED;
  payload: Language
}

export type AppActionTypes = UserFoundAction | LanguageSelectedAction;

我正在将减速器中的AppActionTypes导入,如下所示

import {AppActionTypes} from './app.actions';

并出现以下错误

第4行:在“ store / app / app.actions”中找不到AppActionTypes

下面的链接验证我在做什么是正确的

我正在使用Typescript 3.5.3和babel 7.4

Typescript: Union Type as interface

https://www.typescriptlang.org/docs/handbook/advanced-types.html#union-types

How to type Redux actions and Redux reducers in TypeScript?

0 个答案:

没有答案