Skip to content

JSDoc should be positioned above all overloads when using TypeScript function overloading #1189

@PindaPixel

Description

@PindaPixel

Expected behavior

With the following snippet the TypeScript language service correctly displays the JSDoc when inspecting the function, and I expect jsdoc/require-jsdoc to know the function is documented.

/**
 * @param a Some description
 * @param b Some other description
 * @returns The sum of a and b
 */
function add(a:string, b:string):string;
function add(a:number, b:number): number;
function add(a: any, b:any): any {
    return a + b;
}

Actual behavior

The require-doc rule reports that the function is missing a JSDoc comment and expects the JSDoc to be positioned under the overloads, but this way the TypeScript language service does not display the given docs upon inspection.

function add(a:string, b:string):string;
function add(a:number, b:number): number;
/**
 * @param a Some description
 * @param b Some other description
 * @returns The sum of a and b
 */
function add(a: any, b:any): any {
    return a + b;
}

See TypeScript language service behaviour in this example.

ESLint Config

//eslint.config.js
import jsdoc from "eslint-plugin-jsdoc";

export default [jsdoc.configs["flat/recommended-typescript"]];

Environment

  • Node version: 20.x
  • ESLint version 8.56.0
  • eslint-plugin-jsdoc version: 48.0.2

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions