Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeScript compilation causing dependency errors

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.

like image 560
Matthew Layton Avatar asked Mar 13 '26 20:03

Matthew Layton


1 Answers

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

like image 197
basarat Avatar answered Mar 16 '26 09:03

basarat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!