Skip to content

@type is not always redundant when using a type system #1142

@Lalem001

Description

@Lalem001

Expected behavior

Some types are generics and the default value for the generic variables, if they exist, may not be correct for the usage. An example would be setting the ExecutionContext in AVA's test function:

/**
 * @typedef Context
 * @property {number} foo
 */
const test = /** @type {import('ava').TestFn<Context>} */ (require('ava').default);

test.before((t) => {
  t.context.foo = 42;
});

Typescript marks the above code as valid, and code suggestions work as expected.

Actual behavior

ESLint as configured below, shows a warning for the line t.context.foo = 42;.
The warning is: '@type' is redundant when using a type system jsdoc/check-tag-names

If you remove the @type declaration, then:

  • ESLint is satisfied
  • Typescript throws an error: TS18046:  t.context  is of type  unknown.

ESLint Config

{
  "extends": [
    "plugin:jsdoc/recommended-typescript"
  ]
}

ESLint sample

See the example in Expected behavior above

Environment

  • Node version: v20.3.0
  • ESLint version: v8.46.0
  • eslint-plugin-jsdoc version: 46.4.6

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions