Skip to content
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

noImplicitAny+prototype assignment causes incorrect error on prototype methods #26923

Open
sandersn opened this issue Sep 5, 2018 · 2 comments
Labels
Bug A bug in TypeScript Domain: JavaScript The issue relates to JavaScript specifically
Milestone

Comments

@sandersn
Copy link
Member

sandersn commented Sep 5, 2018

Note that this is only true with noImplicitAny on. The bug does not manifest with it off.
This is a regression in 3.1. It does not manifest in 3.0.

// @noImplicitAny: true
/** @constructor */
var Multimap = function() {
    this._map = {};
};

Multimap.prototype = {
  x() { }
}

Multimap.prototype.lol = function() {
}

var mm = new Multimap();
mm._map
mm.x
mm.lol

Expected behavior:
No error on Multimap.prototype.lol, and _map, x and lol are properties on Multimap.

Actual behavior:
Error: 'lol' does not exist on type '{ x(): void }'. But all 3 are properties on Multimap.

@sandersn sandersn added Bug A bug in TypeScript Salsa labels Sep 5, 2018
@sandersn
Copy link
Member Author

sandersn commented Sep 5, 2018

The solution might be to better understand prototype assignment in getWidenedTypeFromJSPropertyAssignments. I tried calling getJavascriptClassType when there's a prototype assignment, but that resulted in a circularity. Probably a slightly more complex fix will work.

@sandersn sandersn self-assigned this Sep 5, 2018
@RyanCavanaugh RyanCavanaugh added this to the TypeScript 3.3 milestone Oct 9, 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

sandersn commented Mar 13, 2019

This is now fixed.

Edit: Nope, I read expected/actual backward.

@sandersn sandersn reopened this Mar 13, 2019
@sandersn sandersn modified the milestones: TypeScript 3.4.0, Backlog Mar 13, 2019
@sandersn sandersn removed their assignment Jan 7, 2020
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