eslint-plugin- import如何将流声明的模块添加到异常中

时间:2017-08-30 13:04:35

标签: eslint flowtype eslint-config-airbnb

我在flow-typed目录中有一个文件,其中包含一些常见的类型声明:

共types.js

// @flow

declare module 'common-types' {
  declare export type RequestState = {
    setLoading: () => void,
    setFinished: () => void,
    setError: (error: AxiosFailure) => void,
    reset: () => void,
    status: LoadingStatus,
    error: AxiosFailure | void,
  };

  declare export type LoadingStatus = '' | 'loading' | 'finished';

  declare export type ErrorObject = { [key: string]: string | string[] | Error };

  declare export type AxiosFailure = {
    status: number,
    data: ErrorObject,
  }

}

现在我在文件中导入它:

import type { RequestState } from 'common-types';

但是我得到关于缺少文件扩展名的eslint-plugin-import错误以及无法解析模块&#39; common-types&#39; <的路径/ p>

我该如何处理?

1 个答案:

答案 0 :(得分:0)

我找到了解决方案。正如@logansmyth在评论中所建议的那样

  

您的类型应该只将代码与数据一起传递

我遇到的问题是webpack别名。 Flow指出我没有安装模块的错误。 Hovewer I found out我可以在.flowconfig中使用mappers,如:

  $str_date1='30/08/2017';
  $str_date1 = str_replace('/', '-', $str_date1);

  $str_date2='30/10/2017';
  $str_date2 = str_replace('/', '-', $str_date2);
  $date1 = strtotime($str_date1);
  $date1 = date('m/d', $date1);
  $date1 = strtotime($date1);

  $date2 = strtotime($str_date2);
  $date2 = date('m/d', $date2);
  $date2 = strtotime($date2);

if(date1 == $date2){
       //Your code
    }

以及webpack别名,这使得eslint-plugin-import和flow很快以及正确的类型检查。现在我导入类型和module.name_mapper='^common' ->'<PROJECT_ROOT>/src/common' 组件,不会弄乱流式目录。

相关问题