Skip to content

no-undefined-types: false positive for template tags with defaults #887

Closed
@tschaub

Description

@tschaub

Expected behavior

No error.

Actual behavior

The type 'F' is undefined.

ESLint Config

{
  "env": {
    "es6": true
  },
  "parserOptions": {
    "ecmaVersion": "latest",
    "sourceType": "module"
  },
  "plugins": ["jsdoc"],
  "rules": {
    "jsdoc/no-undefined-types": "error"
  },
  "settings": {
    "jsdoc": {
      "mode": "typescript"
    }
  }
}
export class Food {}

export class Soup extends Food {}

export class Donut extends Food {}

/**
 * @template {Food} [F=Soup]
 */
export class Restaurant {
  /**
   * @param {Array<F>} menu The menu items.
   */
  constructor(menu) {
    /**
     * @private
     * @type {Array<F>}
     */
    this.menu = [];
  }
}

Environment

  • Node version: v17.5.0
  • ESLint version v8.0.0
  • eslint-plugin-jsdoc version: 39.3.0

Details

When a template tag is declared like @template {Food} F, the no-undefined-types rule works. If the template tag has a default like @template {Food} [F=Soup], then the no-undefined-types rule does not work.

Support for defaults in template tags was added in TypeScript 4.5 (see microsoft/TypeScript#45483).

Previous improvements to the no-undefined-types rule when using template tags:

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions