Skip to content

In JS, @template types on constructor functions do not resolve in prototype methods #26826

@sandersn

Description

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

/**
 * @param {K} key the key ok
 * @returns {Set<V>} the value ok
 */
Multimap.prototype.get = function (key) {
    return this._map.get(key) || new Set();
}

Expected behavior:
No errors, and Multimap<K,V>.get: (key: K) => Set<V>

Actual behavior:
K and V in @param {K} and @returns {Set<V>} are not found and get: (key: any) => any.

Works fine if Multimap is declared as function Multimap ....

Should work with prototype assignments too, eg Multimap.prototype = { get() { ... } }. Discovered while fixing #24230

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