Skip to content

How to prefer type Object<>, but otherwise object #709

@jaydenseric

Description

@jaydenseric

TypeScript doesn't recognise object<>, but understands Object<>. By default, eslint-plugin-jsdoc prefers the object type over Object. My intent is to prefer object when the type is not using <>, but if it is, prefer Object<>.

  1. Is TypeScript / VS Code intellisense behavior incorrect, and we should push them for a speedy fix?
  2. Should the defaults take this TypeScript / VS Code intellisense behavior into account, and prefer Object<>?
  3. How can that manually be configured, today?

Expected behavior

By default, the types enforced with jsdoc/check-types should be compatible with TypeScript / VS Code intellisense.

Actual behavior

The object<> type is not.

ESLint Config

{
  plugins: ['jsdoc'],
  rules: {
    'jsdoc/check-types': 'error'
  }
}

ESLint sample

To see the problem with the default prefered types, this will be an error:

/** @typedef {Object<string, boolean>} foo */

Screen Shot 2021-03-30 at 12 43 55 pm

To try to allow Object<>:

{
  plugins: ['jsdoc'],
  settings: {
    jsdoc: {
      preferredTypes: {
        'object<>': 'Object',
      },
    },
  },
  rules: {
    'jsdoc/check-types': 'error'
  }
}

Unfortunately, that results a never ending circle of autofix causing another error:

Screen Shot 2021-03-30 at 12 40 42 pm

Screen Shot 2021-03-30 at 12 40 23 pm

Environment

  • Node version: v15.12.0
  • ESLint version v7.23.0
  • eslint-plugin-jsdoc version: v32.3.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions