0

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?

1
  • Can you show us the code? And also the tsconfig? Which module are you using amd or commonjs? Commented Apr 26, 2017 at 9:37

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Great! Adding a reference to the base class resolved the issue - thanks

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.