15

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.

5
  • Is the documentation for the super() constructor call wrong as well? (in my subclasses). I followed the same procedure, but its also stating that my supplied parameters are wrong. Commented Feb 6, 2016 at 17:46
  • Your constructors look fine, what's the actual error? Commented Feb 6, 2016 at 17:49
  • error TS2346: Supplied parameters do not match any signature of call target. Commented Feb 6, 2016 at 17:50
  • @maria: You must have edited your files, because the ones above work for me. Probably just a small typo somewhere. Commented Feb 6, 2016 at 17:51
  • @T.J.Crowder Thank you! Commented Feb 6, 2016 at 17:52

1 Answer 1

27

Replace

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

with

import { A } from './A';

or

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

export class B extends moduleA.A {
  // ...
}
Sign up to request clarification or add additional context in comments.

4 Comments

Where is import...from documented? I don't see it anywhere in typescriptlang.org/Handbook#modules.
The handbook hasn't been updated in quite a while, I don't think it's wrong as such, but there are newer and better ways of doing some things that aren't mentioned in there. I suggest reading github.com/Microsoft/TypeScript/wiki/Breaking-Changes and github.com/Microsoft/TypeScript/wiki/… once you've familiarized yourself with the contents of the handbook.
@VadimMacagon Will do. Thank you!
I've updated my answer to show how the import style used in the handbook would be used.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.