Skip to content

no-undefined-types: bug with @import #1416

@regseb

Description

@regseb

Expected behavior

If I import a type with the JSDoc @import and I use an property of this type, ESLint shouldn't report an error for the jsdoc/no-undefined-types rule.

Actual behavior

ESLint reports error: The type 'Foo.Bar' is undefined

Files

eslint.config.js

import jsdoc from "eslint-plugin-jsdoc";

export default [
  {
    plugins: { jsdoc },
    rules: {
      "jsdoc/no-undefined-types": "error",
    }
  }
];

type.d.ts

export namespace Foo {
    type Bar = string;
}

index.js

/**
 * @import { Foo } from "./type.d.ts"
 */

/**
 * @type {Foo.Bar}
 */
const baz = 42;

package.json

{
  "name": "testcase",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "eslint": "9.29.0",
    "eslint-plugin-jsdoc": "51.2.1",
    "typescript": "5.8.3"
  }
}

To reproduce

  1. npm install

  2. npx eslint

    /home/regseb/testcase/index.js
      6:1  error  The type 'Foo.Bar' is undefined  jsdoc/no-undefined-types
    
    ✖ 1 problem (1 error, 0 warnings)
    

Environment

  • Node version: v22.15.0
  • ESLint version: v9.29.0
  • eslint-plugin-jsdoc version: 51.2.1

Additional information

Type declaration and import is correct, because TypeScript finds the Bar property and reports type error:

  1. npx tsc --checkJs --noEmit index.js

    index.js:8:7 - error TS2322: Type 'number' is not assignable to type 'string'.
    
    8 const baz = 42;
            ~~~
    
    
    Found 1 error in index.js:8
    

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions