Skip to content

In JS, @template with @typedef is not equivalent to a generic type alias #23745

Description

/**
 * @template T
 * @typedef {[T, T]} TPair
 */
/** @type {TPair<number>} */
var tp = [1,2]

TPair doesn't correctly create a generic type alias.

Expected behavior:

TPair's typedef is equivalent to type TPair<T> = [T, T]

Actual behavior:

TPair's typedef is equivalent to type T; type TPair = [T, T] (where T is unique and inexpressible). So @type {TPair} is legal, but nothing can be assigned to it, and @type {TPair<number>} says that TPair is not generic.

Activity

  1. sandersn commented on Apr 27, 2018

    @sandersn
    MemberAuthor

    Note that correctly supporting this may mean breaking old code, since this previously made C generic:

    /** @template T
     * @typedef {T} D
     */
    class C {
    }
    

    And fixing this bug should assign T to the typedef, not the class.

  2. DanielRosenwasser commented on Apr 28, 2018

    @DanielRosenwasser
    Member

    Isn't this a duplicate of #23385 which is supposed to be fixed?

  3. sandersn commented on Apr 30, 2018

    @sandersn
    MemberAuthor

    This is the first repro in #23385, which covered both template tags on classes and on typedefs. Notably, this bug has not come up in real code yet, only in our discussions and webpack’s discussions of style guidelines.

  4. sandersn commented on Apr 30, 2018

    @sandersn
    MemberAuthor

    Basically, there were two bugs to fix, so I went for the one that Sean Larkin (@TheLarkInn) was waiting on. 😸

  5. TheLarkInn commented on Apr 30, 2018

    @TheLarkInn
    Member

    Thanks for submitting this, I wasn't 100% sure it was a bug but got distracted. I'm glad I was right so yay we can fix it! 😍😂

  6. sandersn commented on May 7, 2018

    @sandersn
    MemberAuthor

    Fix is up at #23947

  7. locked and limited conversation to collaborators on Jul 31, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

BugA bug in TypeScriptDomain: JSDocRelates to JSDoc parsing and type generationFixedA PR has been merged for this issue

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions