javascript - 继承和 TypeScript 错误 : X is not a constructor function type

标签 javascript inheritance typescript

我有一个父类(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/

相关文章:

javascript - 在不给 parent 很大宽度的情况下在 slider 中 float 图像的更好方法

javascript - 在 JavaScript 中传递字符串作为参数

python - 在 python 中打印来自父类(super class)的元素

javascript - 更改对象阵列后, ionic 选择选项不会刷新

javascript - 通过 Javascript 更改元素的显示?

c++ - 是什么导致了模板和继承中出现这种令人困惑的编译器错误?

java - 从生成的jaxb类中的抽象Java类实现抽象方法(继承)

javascript - 在 get 函数中绑定(bind)一个 Promise return

javascript - typescript 中对象的通用类型数组

javascript - Angular:样式或类绑定(bind)、座位图