Skip to content

JSDoc @template type parameters aren't resolved on prototype assignments #24230

Closed
@sandersn

Description

@sandersn
/**
 * @constructor
 * @template K, V
 */
var Multimap = function() {
  /** @type {!Map.<K, !Set.<!V>>} */
  this._map = new Map();
};

Multimap.prototype = {
  /**
   * @param {K} key // <------ error here, 'K' not found
   * @param {V} value // <---- and here
   */
  set: function(key, value) {
    var set = this._map.get(key);
    if (!set) {
      set = new Set();
      this._map.set(key, set);
    }
    set.add(value);
  }
}

Expected behavior:
K and V are resolved to the declaration on var Multimap = function ....

Actual behavior:
Cannot find name 'K'. and Cannot find name 'V'.

The js-specific code in resolveEntityName needs to understand prototype assignment the same way that it does prototype property assignment. This works fine:

/**
 * @param {K} key // <------ error here, 'K' not found
 * @param {V} value // <---- and here
 */
Multimap.prototype.set = function {
}

Metadata

Metadata

Assignees

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