Skip to content

Extending ES6 Map causes error - Constructor Map requires 'new' #10853

Closed
@flyon

Description

@flyon

I know native types should be extendable since this PR #3516 , but I can't seem to get extending ES6 Map to work.

The following code

class ResourceMap extends Map {}
var x = new ResourceMap();
x.set('foo',true);

compiles correctly to:

var __extends = (this && this.__extends) || function (d, b) {
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var ResourceMap = (function (_super) {
    __extends(ResourceMap, _super);
    function ResourceMap() {
        _super.apply(this, arguments);
    }
    return ResourceMap;
}(Map));

//[...]
var x = new ResourceMap();
x.set('foo',true);

But when I run it in chrome it gives an error Uncaught TypeError: Constructor Map requires 'new'

When I run the original typescript code directly in the chrome console (which is possible because it's also valid ES6 and only uses functions supported by chrome) then it works correctly. So it should be possible?

Is there a way to extend ES6 Map from Typescript?

Metadata

Metadata

Assignees

No one assigned

    Labels

    ExternalRelates to another program, environment, or user action which we cannot control.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions