Skip to content

Add explicit error to __extends when base class is undefined #5794

Closed
@Arnavion

Description

@Arnavion

We occasionally get people in the IRC channel asking about their transpiled JS failing with TypeError: undefined is not an object. It happens when accessing b.prototype inside __extends because the child class is before the base class, but they often think it's a bug in __extends. Would it make sense to detect if b is undefined at the start of the function and throw an appropriately worded error? Eg:

var __extends = this.__extends || function (d, b) {
    if (b === undefined) { throw new Error("The base class is not defined. Did you put the child class before the base class?"); }
    for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
    function __() { this.constructor = d; }
    __.prototype = b.prototype;
    d.prototype = new __();
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions