Skip to content

Opting out for super call requirement? #9503

@saschanaz

Description

@saschanaz

TypeScript Version: master branch

Code

class EVE extends HTMLElement {
  constructor() {
    return document.createElement("sn-eve"); // Error
  }
}

let eve: EVE;
eve = document.createElement("sn-eve"); // No error

Expected behavior:
It should work if a constructor function return an object which is structurally compatible with the declared class.

Actual behavior:
Error: Constructors for derived classes must contain a 'super' call.

Workaround:

class EVE extends HTMLElement {
  constructor() {
    if ({} === undefined) {
      super();
    }
    return document.createElement("sn-eve");
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    DuplicateAn existing issue was already created

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions