Skip to content

@template tag doesn't work in @typedefs #23385

Description

/**
 * @template {T}
 * @typedef {(x: T, y: T) => number} SetComparer
 */

Expected: x and y have type T
Actual: x any y have type any, and T is associated with whatever declaration follows the JSDoc comment...

For example the following

/**
 * @template {T}
 * @typedef {(x: T, y: T) => number} SetComparer
 */
class C {
}

makes C generic on T.

Activity

  1. TheLarkInn commented on Apr 12, 2018

    @TheLarkInn
    Member

    Tagging my self for watching this Sean Larkin (@TheLarkInn)

  2. sandersn commented on Apr 18, 2018

    @sandersn
    Member

    #23511 fixes your second example, which I believe is the one observed in webpack. It does not fix this example:

    /**
     * @template {V}
     * @typedef {(v: V) => V} Identity
     * @type Identity
     */
    var id = t => t;
    var x = id(1)

    id gets the type (v: V) => V not <V>(v: V) => V, and therefore doesn't infer V=number and instantiate x as number.

  3. sandersn commented on Apr 18, 2018

    @sandersn
    Member

    Never mind, this works.

    /**
     * @typedef {<V>(v: V) => V} Identity
     * @type Identity
     */
    var id = t => t;
    var x = id(1)
  4. locked and limited conversation to collaborators on Jul 30, 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