Skip to content

Support intersection types #545

@chancancode

Description

@chancancode

Motivation

When using TypeScript with JSDoc, the types can be (almost) anything TypeScript supports. This seems to be mostly true already, however, the following doesn't work and give a syntax error:

/**
 * @typedef {object} Foo
 * @property {boolean} isFoo
 *
 * @typedef {object} Bar
 * @property {boolean} isBar
 *
 * @typedef {Foo & Bar} FooAndBar
 *           ~~~~~~~~~ Syntax error in type: Foo & Bar  jsdoc/valid-types
 * 
 * @typedef {Foo | Bar} FooOrBar
 *           ~~~~~~~~~ Ok: union types works
 */

This is not as simple as disabling jsdoc/valid-types. Fundamentally, if this ESLint plugin doesn't understand the intersection type syntax, it will do other things incorrectly. For example, it wouldn't be able to error when Foo or Bar doesn't refer to valid types (e.g. typos), and it can't mark the Foo and Bar values as used to disable the no-unused-vars warning from ESLint.

Current behavior

Syntax error on intersection types X & Y.

Desired behavior

No syntax error on intersection types X & Y, and it understand both X and Y here are type symbols.

Alternatives considered

???

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions