我有一个父类(super class),我希望从中继承其他两个类。下面列出了这些类(class)。当我编译时,试图继承的两个类提示父类(super class)(给出相同的错误): “[类文件路径(在本例中为 A)] 不是构造函数类型”
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);
}
}
这很简单,但是 C 类和 B 类无法编译。我在网上看到的所有示例都没有用于编写这些类/构造函数的任何其他语法。我试图遵循惯例,但似乎无法让它发挥作用。
最佳答案
替换
import A = require('./A');
与
import { A } from './A';
或
import moduleA = require('./A');
export class B extends moduleA.A {
// ...
}
关于javascript - 继承和 TypeScript 错误 : X is not a constructor function type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35244068/