繁体   English   中英

Typescript导入类型Eslint:import / named

[英]Typescript import type Eslint: import/named

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

  • 解析器: @typescript-eslint/parser 1.4.2
  • 插件: @typescript-eslint/eslint-plugin 1.4.2
  • 解析器: eslint-import-resolver-typescript 1.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.ts import { Id } from '../A';import { Id } from '../A';

我试着用:

import A from '../A';

并调用A.Id但是ide throw错误:

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

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

你能帮我解决其中一个问题吗?

预先感谢!

我不认为你的错误与Eslint有关。 从我所看到的,它似乎是一个基本的Typescript错误。

您的A.ts不包含默认导出。 要从A.ts导入整个模块,您应该使用

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

另请参阅import语句Typsescript文档

你试过这个吗?

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM