Skip to content

In JS, can't resolve properties from prototype assignment #26885

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 4, 2018 · 1 comment
Closed

In JS, can't resolve properties from prototype assignment #26885

sandersn opened this issue Sep 4, 2018 · 1 comment
Assignees
Labels
Bug A bug in TypeScript Domain: JavaScript The issue relates to JavaScript specifically

Comments

@sandersn
Copy link
Member

sandersn commented Sep 4, 2018

function Multimap() {
    this._map = {};
};

Multimap.prototype = {
    /**
     * @param {string} key
     * @returns {number} the value ok
     */
    get(key) {
        return this._map[key + ''];
    }
}

/** @type {Multimap} */
const map = new Multimap();
const n = map.get('hi')

Expected behavior:
No error on map.get

Actual behavior:
Error: 'get' not found on type 'Multimap'

I thought there were tests that covered exactly this case, but apparently not. This doesn't work in 3.0 or 3.1.

@sandersn sandersn self-assigned this Sep 4, 2018
@sandersn sandersn added Salsa Add a Flag Any problem can be solved by flags, except for the problem of having too many flags labels Sep 4, 2018
@sandersn sandersn added this to the TypeScript 3.2 milestone Sep 4, 2018
@sandersn sandersn added Bug A bug in TypeScript and removed Add a Flag Any problem can be solved by flags, except for the problem of having too many flags labels Sep 4, 2018
@ghost
Copy link

ghost commented Sep 13, 2018

Note that without the type annotation the type is:

const map: Multimap & {
    get(key: string): number;
}

So get is considered additional to Multimap rather than being a part of it.

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