小编mar*_*ria的帖子

继承和TypeScript出错:X不是构造函数类型

我正在使用一个小型webapp并使用typescript,node.js,express和mongodb.

我有这个超级类,我想要继承其他两个类.课程如下.当我编译时,试图继承的两个类抱怨超类(给出相同的错误):"[类文件路径(在本例中为A)]不是构造函数类型"

A.ts

export class A
{
    //private fields...

    constructor(username: string, password: string, firstName: string,
        lastName: string, accountType: string) 
    {
        // initialisation
    }
}
Run Code Online (Sandbox Code Playgroud)

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);
    }
}
Run Code Online (Sandbox Code Playgroud)

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, …
Run Code Online (Sandbox Code Playgroud)

javascript inheritance typescript

9
推荐指数
1
解决办法
7786
查看次数

标签 统计

inheritance ×1

javascript ×1

typescript ×1