Skip to content

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

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 Sep 17, 2018 · 1 comment
Closed
Assignees
Labels
Bug A bug in TypeScript Domain: JavaScript The issue relates to JavaScript specifically

Comments

@sandersn
Copy link
Member

sandersn commented Sep 17, 2018

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.

@sandersn sandersn self-assigned this Sep 17, 2018
@sandersn sandersn added Bug A bug in TypeScript Salsa labels Sep 17, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.3 milestone Oct 10, 2018
@weswigham weswigham added Domain: JavaScript The issue relates to JavaScript specifically and removed Domain: JavaScript The issue relates to JavaScript specifically Salsa labels Nov 29, 2018
@sandersn
Copy link
Member Author

This is now fixed.

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: JavaScript The issue relates to JavaScript specifically
Projects
None yet
Development

No branches or pull requests

3 participants