typescript-eslint: [import/named] Named type exports are not found

Repro

{
  "rules": {
    // https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/named.md
    // "Note that type imports, as used by Flow, are always ignored."
    "import/named": "error"
  }
}

utils.ts:

export type ResponsiveValue<T = string | number | undefined> =
  | T
  | { [key: number]: T };

export type ResponsiveObject<T> = {
  [K in keyof T]: ResponsiveValue<T[K]>
};

FlexLayout.ts:

import * as CSS from 'csstype';
import { ResponsiveObject } from './utils';

export type Props = ResponsiveObject<{
  flexDirection?: CSS.FlexDirectionProperty;
  flexWrap?: CSS.FlexWrapProperty;
}>;

Expected Result

No warnings should be emitted by ESLint.

Actual Result

[eslint] ResponsiveObject not found in './utils' [import/named] on line 2 of FlexLayout.ts

Versions

package version
@typescript-eslint/eslint-plugin 1.1.0
@typescript-eslint/parser 1.1.0
TypeScript 3.2.4
ESLint 5.12.1
node 10.15.0
npm 6.4.1

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 8
  • Comments: 15 (8 by maintainers)

Commits related to this issue

Most upvoted comments

You shouldn’t need this config. I believe eslint-plugin-import should default to the configured ESLint parser.

If a file extension is matched, the dependency parser will require and use the map key as the parser instead of the configured ESLint parser

yup. but not everyone thinks they’re useless - not everyone uses the typescript compiler to typecheck their code (i.e. some people use babel + webpack), so they rely on eslint tooling to check things like imports.

This is why the import resolver exists - so people can use these tools if they want. I would recommend just disabling it locally if you don’t find value in it.

Thanks for taking the time to write such a comprehensive reply @bradzacher 😄 We’ve got it all working now, we disabled the rule as you suggested.

I believe the intended config is:

{
  "settings": {
    "import/resolver": {
      "typescript": {}
    }
  }
}

You can remove the separate config item "import/parsers", as it will default to eslint’s default parser.

Actually, things seem to work fine when I remove the following:

"import/parsers": {
  "@typescript-eslint/parser": [".ts", ".tsx"]
},

Could the removal affect the quality of code analysis when using eslint-import-resolver-typescript?