gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 04:33:45 27 4
gpt4 key购买 nike

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

common-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 错误

我该如何处理?

最佳答案

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

Your types should just pass your code along with your data

我遇到的问题是 webpack 别名。 Flow 向我指出了有关未安装模块的错误。然而我found out我可以在 .flowconfig 中使用映射器,例如:

module.name_mapper='^common' ->'<PROJECT_ROOT>/src/common'

连同 webpack 别名,这使得 eslint-plugin-import 和 flow 以及适当的类型检查变得愉快。现在,我将类型与 common 组件一起导入,不会弄乱流类型目录。

关于eslint-plugin-import 如何将流声明的模块添加到异常中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45961275/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com