eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

`export import X = Y` seems not being recognized and may trigger `import/namespace` false-positives

Open chenxinyanc opened this issue 2 years ago • 7 comments

Reproduction repo: https://github.com/chenxinyanc/eslint-import-uuid-test

Reproduction code

bar.ts

export const test = 123;

buzz.ts

import * as Bar from "./bar";

export import barTest = Bar.test;

index.ts

import * as Buzz from './buzz';  // No exported names found in module './buzz'. (eslint: import/namespace)

console.log(Buzz);

image

Packages

"devDependencies": {
  "@types/uuid": "^9.0.7",
  "@typescript-eslint/eslint-plugin": "^6.9.1",
  "@typescript-eslint/parser": "^6.9.1",
  "eslint": "^8.55.0",
  "eslint-plugin-import": "^2.29.0",
  "tsc": "^2.0.4",
  "typescript": "^5.3.3"
},

chenxinyanc avatar Dec 08 '23 08:12 chenxinyanc

You should enable synthetic imports and esModuleInterop, otherwise TS's module system is fundamentally broken - if you do that, i suspect you won't need import = ever.

That said, I'm sure we simply have no concept of export import barTest = in the codebase yet since this bizarre TS-only syntax has lots of niche edge cases, so we can certainly add support for it.

ljharb avatar Dec 08 '23 21:12 ljharb

Okay I got it and will try to tweak tsconfig. I'm raising up this question originally because in our project (rather than this small repro) is using the ESM version of the @types/uuid type definitions. See: https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/uuid/index.d.mts

import uuid from "./index.js";
export import v1 = uuid.v1;
export import v3 = uuid.v3;
export import v4 = uuid.v4;
export import v5 = uuid.v5;
export import NIL = uuid.NIL;
export import version = uuid.version;
export import validate = uuid.validate;
export import stringify = uuid.stringify;
export import parse = uuid.parse;

And this is causing eslint-plugin-import thinking there is nothing exported from uuid module. I'm not sure who should fix the issue...

chenxinyanc avatar Dec 11 '23 05:12 chenxinyanc

You should enable synthetic imports and esModuleInterop, otherwise TS's module system is fundamentally broken - if you do that, i suspect you won't need import = ever.

Okay I think I've misread your comment. I cannot really change the export import statements in our situation -- they are inside @types/uuid package. Since you agree this would be a new feature to implement in eslint-plugin-import, I'll instead try to raise up an issue against the typing package in hope they can switch to use some more ordinary re-export statements for now.

chenxinyanc avatar Dec 15 '23 06:12 chenxinyanc

ah, in DT, I believe they're stuck on that syntax.

Either way we need to fix it here.

ljharb avatar Dec 15 '23 06:12 ljharb

ah, in DT, I believe they're stuck on that syntax.

Then I'll hold on for the moment I suppose. Thanks for the information!

chenxinyanc avatar Dec 15 '23 08:12 chenxinyanc

@ljharb any news? it looks like this is a regression of some sort:

"eslint-plugin-import": "^2.27.5"
import { v4 as uuidv4 } from 'uuid'; // All good
"eslint-plugin-import": "^2.29.1",
import { v4 as uuidv4 } from 'uuid'; // error  v4 not found in 'uuid'  import/named

sovcharenko avatar Mar 28 '24 23:03 sovcharenko

@sovcharenko that definitely does seem like one - looking at the package itself, v7 v8 and v9 all have a similar style of "main" file, so it should be working the same.

ljharb avatar Mar 29 '24 06:03 ljharb