Skip to content

Can not extend built in types #1168

Closed
Closed
@mhegazy

Description

@mhegazy

The ES6 designates some native objects as subclassable, e.g. Object, Boolean, Error, Map, Promise ..etc. The way these constructs are modeled in lib.d.ts makes is impossible to subclass, as they are defined as a pair of a var and an interface.

From the ES6 spec section19.5.1:

The Error constructor is designed to be subclassable. It may be used as the value of an extends clause of a class declaration. Subclass constructors that intended to inherit the specified Error behavior should include a super call to the Error constructor to initialize subclass instances.

Currently this would result in "A class can only extend another class" error:

class NotImplementedError extends Error {
    constructor() {
        super("Not Implemented");
    }
}

Metadata

Metadata

Assignees

Labels

BugA bug in TypeScriptES6Relates to the ES6 SpecFixedA PR has been merged for this issue

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions