There is a code in the js file:

// Session ID var hfSessionId = $('[id*=hfSessionId]').val(); // User Id var hfUserId = $('[id*=hfUserId]').val(); 

He works. I write in TypeScript in VisualStudio. How do I write similar code? The compiler swears at the $ sign. I tried to do this:

 module GameVals { // Session ID export var hfSessionId: any = $('[id*=hfSessionId]').val(); // User Id export var hfUserId: any = $('[id*=hfUserId]').val(); } 

Swears "Cannot find name '$'" and do not compile. How to solve a problem? Need to make a separate js file for this code and somehow access it from ts? Or is it necessary to somehow ignore the compiler error? Or am I writing wrong? It seems like you can write js code directly in ts?

    1 answer 1

    $ is obviously something from jQuery, and it needs to be connected. For example:

     npm install --save jquery npm install --save-dev -g typings typings install --save --global dt~jquery. 

    After the typings/index.d.ts you need to add to compile in tsconfig.json.

    • 2
    • Yes, jQuery is connected. Those. If I connect this in ts, then there will be no error on $? - Monax
    • Yes, there will be no errors, as the tsc translator will know about such a function and its type. - Victor Khovanskiy