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

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

Open
chenxinyanc opened this issue Dec 8, 2023 · 7 comments

Comments

@chenxinyanc
Copy link

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"
},
@ljharb
Copy link
Member

ljharb commented Dec 8, 2023

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.

@chenxinyanc
Copy link
Author

chenxinyanc commented Dec 11, 2023

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
Copy link
Author

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.

@ljharb
Copy link
Member

ljharb commented Dec 15, 2023

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

Either way we need to fix it here.

@chenxinyanc
Copy link
Author

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!

@sovcharenko
Copy link

@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

@ljharb
Copy link
Member

ljharb commented Mar 29, 2024

@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 ljharb added the bug label Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants