Typescript导入类型Eslint:导入/命名

hong4rc

我将Eslint用于我的项目,请使用:

  • 解析器:@typescript-eslint/parser1.4.2
  • 插件:@typescript-eslint/eslint-plugin1.4.2
  • 解决:eslint-import-resolver-typescript1.1.1
  • 规则扩展:airbnb-baseplugin:@typescript-eslint/recommended

或者您可以检查我的.eslintrc

{
  "parser": "@typescript-eslint/parser",
  "plugins": [
    "@typescript-eslint"
  ],
  "extends": ["airbnb-base", "plugin:@typescript-eslint/recommended"],
  "settings": {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts"]
    },
    "import/resolver": {
      "typescript": {}
    }
  },
  "rules": {
    "no-plusplus": "off",
    "import/no-cycle": "warn",
    "@typescript-eslint/indent": ["error", 2],
    "@typescript-eslint/explicit-member-accessibility": "off"
  }
}

在文件中,A.ts我使用:export type Id = string;并从导入B.tsimport { Id } from '../A';

我尝试使用:

import A from '../A';

并调用A.Id但ide抛出错误:

A仅指类型,但在此处被用作名称空间

两种方法都有错误,一种来自eslint,一种来自IDE(Vs Code,也许是Tshint)

您能帮我修复其中一个吗?

预先感谢!

霍尔格·施密茨(Holger Schmitz)

我不认为您的错误与Eslint有关。从我可以看到,这似乎是一个基本的Typescript错误。

A.ts不包含默认导出。为了从中导入整个模块,A.ts应使用

import * as A from '../A';

另请参见关于语句Typsescript文档import

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章