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

Handle TSExportAssignment exports other than namespaces #1527

Closed
joaovieira opened this issue Oct 30, 2019 · 5 comments · Fixed by #1528 or #1689
Closed

Handle TSExportAssignment exports other than namespaces #1527

joaovieira opened this issue Oct 30, 2019 · 5 comments · Fixed by #1528 or #1689

Comments

@joaovieira
Copy link
Contributor

joaovieira commented Oct 30, 2019

At the moment eslint-plugin-import only handles the export = syntax in TypeScript if it references a namespace.

Using @types/supertest as an example. The module definition is:

import * as superagent from "superagent"

export = supertest;

declare function supertest(app: any): supertest.SuperTest<supertest.Test>;
declare namespace supertest {...}

And the generated ExportMap is:

ExportMap {
  path: '/Users/joaovieira/.../node_modules/@types/supertest/index.d.ts',
  namespace: Map {
    'Response' => {},
    'Request' => {},
    'CallbackHandler' => {},
    'Test' => {},
    'AgentOptions' => {},
    'agent' => {},
    'SuperTest' => {}
  },
  reexports: Map {},
  dependencies: Set {},
  imports: Map {
    '/Users/joaovieira/.../node_modules/@types/superagent/index.d.ts' => { getter: [Function], source: [Object], importedSpecifiers: [Set] }
  },
  errors: []
}

Only the namespace is being exported. The declared function with the same name is not added to the exported namespace as 'default'.

Looking at the code, it is explicitly only handling namespaces.

This means, user code such as:

import request, { Test } from 'supertest';

Raises an eslint error No default export found in module.eslint(import/default).


The same issue happens when the module re-exports an identifier as in @types/lodash. The module definition is:

import { snakeCase } from "./index";
export = snakeCase;

The ExportMap in this case is an empty object:

ExportMap {
  path: '/Users/joaovieira/.../node_modules/@types/lodash/snakeCase.d.ts',
  namespace: Map {},
  reexports: Map {},
  dependencies: Set {},
  imports: Map {
    '/Users/joaovieira/.../node_modules/@types/lodash/index.d.ts' => { getter: [Function], source: [Object], importedSpecifiers: [Set] }
  },
  errors: []
}

So, this fails:

import camelCase from 'lodash/camelCase';

Both are very common patterns in DefinitelyTyped.

@maribies
Copy link

I believe there is a related issue here with React Navigation import errors, see the issue opened here: eslint/eslint#12761. A work around is to ignore the imports for the react navigation, but this is not desirable long term. Any suggestions? Thanks.

@PatricSachse
Copy link

Facing the exact same issue... Help is highly appreciated! :)

@joaovieira
Copy link
Contributor Author

@maribies @PatricSachse your issue seems to have been resolved in react-navigation itself react-navigation/react-navigation#6506.

@maribies
Copy link

maribies commented Feb 5, 2020

@joaovieira - just tried bumping to 4.1.1 and am having the same errors. i'm having my team review in case i missed something and @PatricSachse - if you bump and it resolves please let us know!

@joaovieira
Copy link
Contributor Author

@maribies would you mind continuing this conversation in that issue? thanks

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