Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import of Typescript interface is not recognised correctly #1120

Closed
majelbstoat opened this issue Jun 14, 2018 · 13 comments
Closed

Import of Typescript interface is not recognised correctly #1120

majelbstoat opened this issue Jun 14, 2018 · 13 comments

Comments

@majelbstoat
Copy link

majelbstoat commented Jun 14, 2018

Opening per @ljharb. A similar issue was reported in #726, but this is for Typescript interface imports.

Defined in react-select:

export interface Option<TValue = OptionValues> { // ... }

Imported:

import Select, { Option } from 'react-select'

Error:

[eslint] Option not found in 'react-select' (import/named)

Relevant packages:

    "eslint": "4.19.1",
    "eslint-plugin-import": "2.12.0",
    "typescript": "2.9.1",
    "typescript-eslint-parser": "16.0.0"
@ljharb
Copy link
Member

ljharb commented Jun 15, 2018

Historically eslint (and thus, eslint plugins) have only supported Flow, not TypeScript.

I think adding typescript support is a pretty massive effort, but if it can be done easily, that sounds fine.

@mockdeep
Copy link

Just ran into this, too:

import moment, {Moment} from 'moment';

error:

1:17  error  Moment not found in 'moment'             import/named

@ljharb
Copy link
Member

ljharb commented Oct 14, 2018

In that case, moment is CJS, so it only has a default export.

@mockdeep
Copy link

mockdeep commented Oct 14, 2018

TypeScript also pulls in the type information from it's .d.ts file:

https://github.com/moment/moment/blob/develop/moment.d.ts#L413

@Jessidhia
Copy link

Jessidhia commented Feb 8, 2019

#1282 is nearly a duplicate of this, but this issue also includes types provides through external .d.ts files.

I'm not sure if it is possible to deal with this 100% correctly without a full type checker pass; a possible workaround is to check if there is a .d.ts available for parsing its imports instead before checking other extensions, but that won't work with declare module-style declarations (which can declare any module name they want if they're in ambient context).

@typescript-eslint/eslint-plugin will either need its own rule for this, or eslint-plugin-import should be taught to make use of the type services from @typescript-eslint/parser when they are available instead of using its own resolver/parser.

@Primajin
Copy link

After upgrading to 2.17.1 this is fixed for me 🎉

@ljharb
Copy link
Member

ljharb commented Apr 16, 2019

Awesome, closing (happy to reopen if people are still experiencing it)

@ljharb ljharb closed this as completed Apr 16, 2019
@alesn
Copy link

alesn commented Apr 17, 2019

Unfortunately, this issue still exists in 2.17.2 (using @typescript-eslint/parser as recommended in the Typescript section of eslint-plugin-import Readme [not the now deprecated typescript-eslint-parser mentioned in the configuration above])

@kachkaev
Copy link

@alesn would you mind opening a new issue and shading a minimal reproduction?

@alesn
Copy link

alesn commented Apr 17, 2019

Has this issue been resolved for anyone who uses @typescript-eslint/parser, which should now be used?

@Primajin
Copy link

I will double check that and let you know

@Primajin
Copy link

@alesn Sorry I forgot to answer you earlier.

Yes I am running "@typescript-eslint/parser": "^1.6.0" and "eslint-plugin-import": "^2.17.1".
There is also 2.17.2 out in the meantime.

In .eslintrc.js I have

parser: '@typescript-eslint/parser',
overrides: {
  files: ['**/*.ts', '**/*.tsx'],
  parser: '@typescript-eslint/parser',
  rules: {
    'import/namespace': 'off',
    'import/no-duplicates': 'off',
    'import/no-unresolved': 'off',
    'no-restricted-globals': 'off',
    'no-undef': 'off'
  }
},

Hope that helps.

@cloakedninjas
Copy link

For anyone arriving from Google - you can work around this with a tip from #1699

Although now that import type exists, I'd suggest using that.

import type { unitOfTime } from 'moment';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

8 participants