How to cache external Javascript files?

Is there a tool or procedure to convert Javascript files to Typescript?

  • I am trying to convert my NodeJS + Express + JQuery project to Typescript and in the process I have to convert plenty of javascript code to typescript header files to enable intellisense in Webstorm which is the IDE I'm using. I am unable to find a tool that does this automatically OR a well defined procedure for converting .js to .ts or .d.ts (header file). Especially I’m interested in converting. 1.    NodeJS modules on the server side 2.    JQuery plugins on the client side 3.    .js files in general on either side To typescript header files – (.d.ts) I'm hoping somebody can write a procedure to create typescript definitions out of javascript code.

  • Answer:

    No, you can't directly use your old JS code straightaway in TypeScript file. You need to resolve dependencies of other file reference in your JS code by giving references in your TS file. Eg. //reference path = "file.js" You need to define specific types like array, object etc or have to declare it as 'any'. It will not be possible to iterate on var object of your JS without changing it to array or something. There should be proper interface or classes for complex objects Eg. customer.name will not work if there is not Interface Customer having Name in it. There should not be any undeclared variable in your TS file eg. a,b should be var a, string b etc You will have to include the declaration files for the libraries you are using eg. Jquery.d.ts. Refer here for importing the declaration file for commonly used js libraries https://github.com/borisyankov/DefinitelyTyped Typescript is the superset of Javascript with strictly typed definations, its compiler compiles your TS file to JS files, so you TS file should be free from any compile time errors before its respective js file is made.

Shobhit Ghai at Quora Visit the source

Was this solution helpful to you?

Other answers

Resharper 9 can do it. Rename your .js file to .ts and then use the Resharper context menus.

Jonas Gauffin

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.