microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.1k stars 12.37k forks source link

TS2377 reported for constructors that unconditionally throw or use return override #33927

Open ExE-Boss opened 4 years ago

ExE-Boss commented 4 years ago

TypeScript Version:

3.7.0-dev.2019-10-10

Search Terms:

Code

Code like this is also generated by webidl2js:

class Foo extends Object {
    constructor () {
        throw new TypeError("Illegal constructor");
    }
}

Same with

class Foo extends Object {
    constructor () {
        return Object.create(new.target.prototype);
    }
}

Expected behavior:

No error

Actual behavior:

error TS2377: Constructors for derived classes must contain a 'super' call.

2     constructor() {
      ~~~~~~~~~~~~~~~
3         throw new TypeError();
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4     }
  ~~~~~

and

error TS2377: Constructors for derived classes must contain a 'super' call.

2     constructor() {
      ~~~~~~~~~~~~~~~
3         return Object.create(new.target.prototype);
  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4     }
  ~~~~~

Playground Link:

🔗

Related Issues:

ExE-Boss commented 4 years ago

This also occurs with class constructors that use the return override trick.