Eslint-plugin-import: Handle TSExportAssignment exports other than namespaces

Created on 30 Oct 2019  路  5Comments  路  Source: benmosher/eslint-plugin-import

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.

help wanted typescript

Most helpful comment

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

All 5 comments

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

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

@maribies @PatricSachse your issue seems to have been resolved in react-navigation itself https://github.com/react-navigation/react-navigation/issues/6506.

@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!

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

Was this page helpful?
0 / 5 - 0 ratings