Skip to content

Object literal methods in prototype assignments don't have correct this-type #26831

Closed
@sandersn

Description

@sandersn
// @noImplicitAny: true
/**
 * @constructor
 * @template {string} K
 * @template V
 */
// function Multimap() {
var Multimap = function() {
    /** @type {Object<string, V>} TODO: Remove the prototype from the fresh object */
    this._map = {};
};

Multimap.prototype = {
  /**
   * @param {K} key
   * @param {V} value
   */
  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:

No errors on this._map references.

Actual behavior:

Property '_map' doesn't exist on type { set(key: K): V }.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions