Skip to content

[no-unused-modules] Dynamic import doesn't mark exports as used #1951

@phaux

Description

@phaux

Repro:

// foo.ts
export const foo = "foo"

// index.ts
async function test() {
  const { foo } = await import("./foo")
  const foo2 = await import("./foo").then(mod => mod.foo)
  const mod = await import("./foo") // should mark all non-type exports as used
}

My specific use case is:

import { lazy } from "react"
const Foo = lazy(() => import("./Foo"))

exported declaration 'foo' not used within other modules

Config:

{
  "extends": [
    "plugin:import/recommended",
    "plugin:import/typescript",
    // and more ...
  ],
  "rules": {
    "import/no-unused-modules": ["error", { "unusedExports": true }],
  },
}

Versions:

@typescript-eslint/parser: 4.8.0
eslint: 7.13.0
eslint-plugin-import: 2.22.1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions