Reputation: 153
I have this super class that I want two other classes to inherit from. The classes are listed below. When I compile, the two classes trying to inherit complain about the superclass (the give the same error): "[class file path (in this case A)] is not a constructor function type"
A.ts
export class A
{
//private fields...
constructor(username: string, password: string, firstName: string,
lastName: string, accountType: string)
{
// initialisation
}
}
B.ts
import A = require('./A);
export class B extends A
{
constructor(username: string, password: string, firstName: string,
lastName: string, accountType: string)
{
super(username, password, firstName, lastName, accountType);
}
}
C.ts
import A = require('./A );
export class C extends A
{
constructor(username: string, password: string, firstName: string,
lastName: string, accountType: string)
{
super(username, password, firstName, lastName, accountType);
}
}
This is pretty simple, and yet Class C and B cannot compile. All the examples I have seen online do not have any other syntax for writing these classes/ constructor. I am trying to follow convention, but can't seem to get it to work.
Upvotes: 15
Views: 23676
Reputation: 14847
Replace
import A = require('./A');
with
import { A } from './A';
or
import moduleA = require('./A');
export class B extends moduleA.A {
// ...
}
Upvotes: 27