Skip to content

JSDoc of base class/interface appears many times when using union of derived class/interface #32708

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
AnyhowStep opened this issue Aug 5, 2019 · 5 comments · Fixed by #34522
Assignees
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fix Available A PR has been opened for this issue

Comments

@AnyhowStep
Copy link
Contributor

AnyhowStep commented Aug 5, 2019

TypeScript Version: 3.5.1

Search Terms:

JSDoc, duplicate, extends, implements

Code

interface InterfaceFoo<DataT extends { name : string }> {
    /**
     * Some comment
     * 
     * -----
     */
    name : DataT["name"]
}

class ClassFoo<DataT extends { name : string }> implements InterfaceFoo<DataT> {
    name! : DataT["name"]
}

///////////////////////
declare const arr2 : readonly (
    | ClassFoo<{name:"X"}>
    | ClassFoo<{name:"Y"}>
)[];
/*
Expected:
Some comment

Actual:
Some comment
-----
Some comment
-----
*/
arr2[0].name

///////////////////////
declare const arr3 : readonly (
    | ClassFoo<{name:"X"}>
    | ClassFoo<{name:"Y"}>
    | ClassFoo<{name:"Z"}>
)[];

/*
Expected:
Some comment

Actual:
Some comment
-----
Some comment
-----
Some comment
-----
*/
arr3[0].name

Expected behavior:

Some comment should only appear once

Actual behavior:

Some comment appears n times if the array contains ClassFoo<> n times

Playground Link:

Playground

Related Issues:

No idea

@AnyhowStep
Copy link
Contributor Author

image

Playground

@AnyhowStep
Copy link
Contributor Author

AnyhowStep commented Aug 5, 2019

It seems like it has something to do with the implements/extends keyword.

Changing class ClassFoo implements to interface ClassFoo extends gives the same result,
Playground


Using InterfaceFoo directly is fine,
Playground

@AnyhowStep AnyhowStep changed the title JSDoc comment duplicated multiple times JSDoc of base class/interface appears many times when using union of derived class/interface Aug 5, 2019
@AnyhowStep
Copy link
Contributor Author

In my current project, I end up having a very looooooong tooltip,
image

You can see the scroll bar on the right side of the tooltip.

@AnyhowStep
Copy link
Contributor Author

AnyhowStep commented Aug 5, 2019

Shorter repro,

interface InterfaceFoo<DataT extends { name : string }> {
    /**
     * Appear only once plz
     */
    name : DataT["name"]
}

class ClassFoo<DataT extends { name : string }> implements InterfaceFoo<DataT> {
    name! : DataT["name"]
}

///////////////////////
declare const unionType : (
    | ClassFoo<{name:"X"}>
    | ClassFoo<{name:"Y"}>
);
/*
Expected:
Appear only once plz

Actual:
Appear only once plz Appear only once plz
*/
unionType.name

Playground

[Edit]

I actually like this repro more,
Playground


I feel like it should know that they all come from InterfaceFoo and not duplicate it.

It might make sense if the types in the union were all unrelated.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Aug 5, 2019
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.7.0 milestone Aug 5, 2019
@sandersn sandersn added Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation and removed Needs Investigation This issue needs a team member to investigate its status. labels Oct 16, 2019
sandersn added a commit that referenced this issue Oct 16, 2019
JSDoc on own properties was already deduped, but inherited jsdoc was
incorrectly not deduped.

Fixes #32708
@sandersn sandersn added the Fix Available A PR has been opened for this issue label Oct 16, 2019
@sandersn
Copy link
Member

Oops. We dedupe non-inherited jsdoc but forgot to do the same for inherited jsdoc.

sandersn added a commit that referenced this issue Oct 16, 2019
JSDoc on own properties was already deduped, but inherited jsdoc was
incorrectly not deduped.

Fixes #32708
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fix Available A PR has been opened for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants