typescript - 仅类型导入与无重复导入 eslint 规则冲突

标签 typescript eslint typescript-eslint type-only-import-export

我有一个像这样的 PropsTypes.ts 文件:

export interface ImageSrc { url: string; originUrl: string }

export default interface PropsType {
  images: Array<ImageSrc> | Array<string>;
  visible: boolean;
  activeIndex?: number;
  showPagination?: boolean;
  maxScale?: number;
  minScale?: number;
  onChange?: Function;
  onClose?: Function;
}

我正在使用type-only-imports-and-export TypeScript 3.8 的功能。

import type PropsType from './PropsType';
import type { ImageSrc } from './PropsType';

但是 eslint 会抛出错误:

'./PropsType' imported multiple times. eslint(import/no-duplicates)

我预计 eslint 应该满足仅类型导入和导出的规则。 有没有办法在不禁用它的情况下满足这个 eslint 规则?

最佳答案

使用 typescript-eslint 插件中的 @typescript-eslint/no-duplicate-imports 规则:https://typescript-eslint.io/rules/no-duplicate-imports/

关于typescript - 仅类型导入与无重复导入 eslint 规则冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66366815/

相关文章:

typescript - Jest 错误: "preset @vue/cli-plugin-unit-jest/presets/typescript-and-babel not found"

javascript - 如何处理模块和 typescript 类型的 Jest 模拟功能

typescript - 停止 typescript-eslint/explicit-module-boundary-types 应用于不使用 Typescript 的 vue 组件

create-react-app - 解析错误 : '=' expected in `import type`

javascript - 使用过滤器函数从 API 返回过滤结果列表

javascript - 如何在我的 React Typescript 计数器中使用类型接口(interface)来支持钻取?

javascript - 对先前声明的变量进行解构赋值时出现 linter 错误 "Unexpected token ="

javascript - Eslint 的正确 YAML - 值不应超过 1 个项目 - 无多个空行

javascript - 忽略 moment.js 的 eslint 错误

typescript - 如何配置@ typescript-eslint规则