Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
77
rated 0 times [  83] [ 6]  / answers: 1 / hits: 35263  / 10 Years ago, fri, october 17, 2014, 12:00:00

On our big enterprise project we faced a situation that seems not to be very well described in the articles and the posts available in the Internet.



We need to integrate our existing JavaScript infrastructural code that supports SPA with the code that is being developed by the other team on TypeScript. We can’t drastically change the approach (i.e. just pick a single language) for many political limitations and the development resources available. And we fully understand that’s probably it’s not a good idea to integrate two pieces of infrastructure together that are written on different languages.



Still we need to evaluate the impact and best practices of calling TypeScript from JavaScript code.



The justification that TypeScript is essentially compiled into JavaScript seems to be obscure because there are no trustful sources on information on the topic on how to properly consume that compiled JavaScript from handwritten JavaScript and what are the hidden caveats (or alternatives).



It also seems that the opposite situation when TypeScript code needs to call JavaScript is surprisingly very well described.



Any profound thoughts on the topic?



UPD



Specifically here is the list of questions we are seeking the answers now:




  • what will be the JavaScript shape of the TypeScript API that extensively uses generics, class hierarchies, interfaces?

  • are there any issues with bundling, minification, AMD?

  • is it possible to have the basic Angular controller written in TypeScript and the other JavaScript Angular controller that inherits the functionality from it? What will be the caveats?



Actually we think that we haven't surfaced all the questions yet. They've emerged just after a couple of hours of thinking on that topic.


More From » typescript

 Answers
1

Simply said, if you have to integrate/use a library which is written in Typescript in your own project which uses JavaScript, you will use the compiled JavaScript API!



You basically throw away everything which TypeScript brings in terms of benefit over pure JavaScript.



Meaning you don't have to care about anything specific to TypeScript, like generics etc. You only have to work with the compiled output of the TypeScript library...



To give you an example, go to http://www.typescriptlang.org/Playground
Select Walkthrough: Generics. On the right you should see the compiled JavaScript. It has no generics or anything special, it still is pure JavaScript. That's what you have to deal with...



to your specific questions:




  • what will be the JavaScript shape of the TypeScript API that extensively uses generics, class hierarchies, interfaces? See above. It will be plain good old Javascript. No difference for you.

  • are there any issues with bundling, minification, AMD? No, because compiled TypeScript is plain JavaScript and can be minified etc...

  • is it possible to have the basic Angular controller written in TypeScript and the other JavaScript Angular controller that inherits the functionality from it? What will be the caveats?
    Yes of course you can do whatever you want with the compiled JavaScript.



The only disadvantage of using the compiled JavaScript from Typescirpt is, that you throw away the awesome features TypeScript can give you, like... types...
If the other team is already on that route, you may want to consider to write your part in TypeScript as well ;)


[#69090] Wednesday, October 15, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
heidys

Total Points: 665
Total Questions: 102
Total Answers: 97

Location: Belarus
Member since Sat, Jul 18, 2020
4 Years ago
;