Skip to content

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

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
sandersn opened this issue May 17, 2018 · 1 comment · Fixed by #26830
Closed

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

sandersn opened this issue May 17, 2018 · 1 comment · Fixed by #26830
Assignees
Labels
Bug A bug in TypeScript Domain: JSDoc Relates to JSDoc parsing and type generation Fixed A PR has been merged for this issue

Comments

@sandersn
Copy link
Member

/**
 * @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 {
}
@sandersn
Copy link
Member Author

Note: This does not work fine, given the current example:

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

It only works if Multimap is declared as function Multimap ... instead of var Multimap = function ....

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 Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants