-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Forced to call super leading to undefined is not a constructor #21761
Copy link
Copy link
Closed
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code
Description
TypeScript Version: 2.7.1
Search Terms:
super constructor undefined
Code
tsconfig.json
{
"compilerOptions": {
"declaration": true,
"downlevelIteration": true,
"experimentalDecorators": true,
"lib": [ "esnext", "dom" ],
"module": "es2015",
"moduleResolution": "node",
"noUnusedLocals": true,
"noUnusedParameters": true,
"removeComments": true,
"skipLibCheck": true,
"sourceMap": true,
"target": "es5"
}
}type Constructor<T = {}> = new( ...args: any[] ) => T;
class Null extends null { }
interface MyInterface {
myMixinMethod(): void;
myClassMethod(): void;
}
const MyMixin = <T extends Constructor>( superclass: T ) => class extends superclass {
myMixinMethod(): void {
console.log( 'Called my mixin method' );
}
};
abstract class AbstractMyClass extends MyMixin( Null ) implements MyInterface {
abstract myClassMethod(): void;
}
class MyClass extends AbstractMyClass {
constructor( public myProperty: string ){
// If super() is not called, it throws the error below
// [ts] Constructors for derived classes must contain a 'super' call.
super();
}
myClassMethod(): void {
console.log( 'Called my class method' );
}
}
// If super() is called in MyClass, it throws the error below
// TypeError: undefined is not a constructor (evaluating '_super.call(this)')
const myClass = new MyClass( 'myValue' );Expected behavior:
It should not require the super() call since parent class lacks a constructor.
Actual behavior:
It requires a call to super() which results in the error undefined is not a constructor.
Related Issues:
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
QuestionAn issue which isn't directly actionable in codeAn issue which isn't directly actionable in code