Chris B
Chris B

Reputation: 5441

TypeScript Inheritance - "A class must be declared after its base class"

Working with TypeScript 2.2 in VS2015 I have a base class with a derived class which in turn has a derived class.

When compiling I receive an error that "A class must be declared after its base class". Each of the classes are in their own files so it appears that they are compiled in alphabetical order because if I rename the base class with "aa" so it comes first alphabetically then the solution compiles.

I could (and originally did) have all the classes in one file, in that case I can control the order but I don't want to have to put all the derived classes in the same file.

Am I doing something wrong here, shouldn't it compile the lowest dependency first?

Upvotes: 0

Views: 484

Answers (1)

user6848348
user6848348

Reputation:

The compiler does not reorder emitted code. the files are emitted in order supplied on the commandline and through resolving /// <references>. you can either move the derived class definition to be after the base, or add a /// <reference> tag to the file with the derived class pointing to the file with the base class to ensure correct emit order.

Upvotes: 1

Related Questions