Error with inheritance and TypeScript: X is not a constructor function type

I am working on a small webapp and use typescript, node.js, express and mongodb.

I have this superclass that I want to get from two other classes. Classes are listed below. When I compile, two classes trying to inherit complain about the superclass (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);
    }
}

It's pretty simple, and yet classes C and B cannot compile. All the examples I've seen on the Internet have no other syntax for writing these classes / constructors. I am trying to follow a convention, but it seems like I can't get it to work.

Any help would be greatly appreciated! Thanks for reading.

+4
1

import A = require('./A');

import { A } from './A';

import moduleA = require('./A');

export class B extends moduleA.A {
  // ...
}
+8

Source: https://habr.com/ru/post/1627585/


All Articles