refactor refactor - 5 months ago 47
TypeScript Question

Referencing external JS library in typescript

I would like to use Jquery library in my type script(.ts) file , and I using
atom editor.

To implement this I have followed below steps

  1. Since I am using atom editor , installed apm install atom-typescript

  2. Since Jquery is external JS library , I have dowloaded typed defination
    from here and placed the file in my application folder

3 Added reference to jquery.d.ts" in my test.ts file

Below is the test.ts code

/// <reference path="./node_modules/jquery/dist/jquery.d.ts" />

export class test {
$("#testID").val("test"); // editor shows ERROR in this line , "parameter declaration expected"

Please let me know what is that I am missing.

Answer Source

Instead of copy-pasting the definition file, it is considered best practice to use typings instead. Typings handles a lot for you, eg. you won't have to think about referencing the proper path.

So just run typings init and typings install --save --global dt~jquery and you should be good to go.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download