简体   繁体   中英

Typescript import type Eslint: import/named

I use Eslint for my project, use:

  • parser: @typescript-eslint/parser 1.4.2
  • plugin: @typescript-eslint/eslint-plugin 1.4.2
  • resolver: eslint-import-resolver-typescript 1.1.1
  • rule extends: airbnb-base and plugin:@typescript-eslint/recommended

or you can check my .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"
  }
}

In file A.ts I use: export type Id = string; and import from B.ts : import { Id } from '../A';

I tried to use:

import A from '../A';

and call A.Id but ide throw error:

A only refers to a type, but is being used as a namespace here

Two way has an error, one from eslint , one from IDE (Vs Code, maybe Tshint)

Can you help me fix one of them?

Thank in advance!

I don't think that your error is related to the Eslint. From what I can see, it seems to be a basic Typescript error.

Your A.ts does not contain a default export. In order to import the entire module from A.ts you should use

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

See also the Typsescript documentation on import statements

你试过这个吗?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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