TypeScript compilation throwing dependency errors

I am compiling multiple TypeScript files into one JavaScript file. Let's 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 the problem: The TypeScript function __extends

failed due to passing a value undefined

.

The compilation had to be 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 (in alphabetical order), not in dependency order.

  • Can this be solved?
  • Is this issue reported to the TypeScript team?

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

+3


source to share


2 answers


but unfortunately they were compiled according to their names (in alphabetical order) and not in dependency order

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



TypeScript does not automatically arrange files. You have to compile some flag --module

for example. commonjs

and then let the external module loader resolve these networks of dependencies for you.

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

+1


source


For the compiler to concatenate the files in the correct order, you must use pivot tags in every file that depends on other files. This will allow the compiler to plot the dependencies of your resources and sort them correctly if you don't have circular dependencies.

Another option is to manually sort the input in the compiler, giving it a complete sorted list of all files, or using _references.ts to determine at least the first set of files to load in order.



Learn more about how it works here .

0


source







All Articles