3

I am compiling multiple TypeScript files into a single JavaScript file. Say for example they are called:

A.ts // depends on C.ts
B.ts // depends on C.ts
C.ts

When I checked the JavaScript output, I found a problem: TypeScript's __extends function failed due to being passed an undefined value.

Compilation should have been in the following order:

C.ts // because A and B depend on this respectively.
A.ts
B.ts

but unfortunately they were compiled according to their names (alphabetically) rather than in dependency order.

  • Can this be solved?
  • Is the TypeScript team aware of this issue?

Note: This is a Visual Studio TypeScript compiler issue. Presumably using the command line compiler would fix this, but I would like to compile from Visual Studio.

3
  • Sidenote: Read "--out is bad" from basarat. Commented Jul 14, 2015 at 17:31
  • Note that Visual Studio is using the same typescript compiler as the command line, there is no difference there. Commented Feb 16, 2016 at 8:48
  • Consider marking one answer as accepted or request more information in order to answer your question :) Commented Apr 6, 2016 at 17:57

2 Answers 2

1

but unfortunately they were compiled according to their names (alphabetically) rather than in dependency order

https://github.com/TypeStrong/atom-typescript/blob/master/docs/out.md

TypeScript doesn't do automatic file ordering. You should compile with some --module flag set e.g. commonjs and then let an external module loader resolve these dependency chains for you.

More : http://basarat.gitbooks.io/typescript/content/docs/project/modules.html

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

Comments

0

For the compiler to merge the files in the correct order, you have to use reference tags in each file that is dependent on other files. This will make it possible for the compiler to do a dependency graph of your resources and sort them properly so long as you don't have any cyclic dependencies.

Your other option is to manually sort the input to the compiler, either by giving it a full sorted list of all files, or using a _references.ts to define at least the first set of files to load in order.

Read more about how this works here.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.