Skip to content

In JS, prototype assignment to property of expando type changes type reference #27146

Closed
@sandersn

Description

@sandersn
var UI = {}
UI.Hunch = class {
    constructor() {
    }
}
UI.Hunch.Provider = function() {};
UI.Hunch.Provider.prototype = {
  /**
   * @return {void}
   */
  item() {}
};

/**
 * @returns {UI.Hunch}
 */
function failure() {
    return new UI.Hunch();
}

Expected behavior:
The value new UI.Hunch() is assignable to the return type reference UI.Hunch.

Actual behavior:
Error: Hunch is not assignable to { item: () => void } & { item: () => void }

Looks like Providers prototype assignment confuses the type reference to UI.Hunch.

Discovered in chrome-devtools-frontend, but it's been this way for a long time. Not a recent regression.

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptDomain: JavaScriptThe issue relates to JavaScript specifically

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions