Skip to content

Duplicate JSDoc in union of derived interfaces #43213

@sandersn

Description

@sandersn
interface I {
    /** The colour */
    readonly colour: string
}
interface A extends I {
    readonly colour: "red" | "green";
}
interface B extends I {
    readonly colour: "yellow" | "green";
}
type F = A | B
const f: F = { colour: "green" }
f.colour/**/

Expected behavior:

Quickinfo at /**/

(property) I.colour: string

The colour

Actual behavior:

(property) I.colour: string

The colour
The colour

From my notes on discord explaining to the person who noticed this:

The function in the TS services is called getDocumentationComment, and it does three things:

  1. calls another function to get the comment text to display
  2. loops over each declaration after uniquifying
  3. per-declaration, gets the comment text from the base, if there is any

For the example above, colour has two declarations, since it's a union: Apple.colour and Banana.colour. So:

Step 1. No comment text from either declaration.
Step 2. There are two unique declarations to iterate over.
Step 3. Each declaration has the same base, which contributes the same comment.

#35170 has separate jsdocs for each, as you point out.
#32708 only has one extended declaration, just instantiated with two generic types

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptGood First IssueWell scoped, documented and has the green lightHelp WantedYou can do this

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions