How to use jQuery with Typescript

 jQuery's type support works better than most articles on the internet. ( I believe. )


first:

npm install jquery --save

npm install @types/jquery --save-dev


second( very very very important ! ! ! ):

import jquery = require("jquery");


//  this helps TypeScript to understand jQuery best !!!  otherwise It will confused.

const $: JQueryStatic = jquery;



Now , You Can Enjoy It :

$(document).ready(function () {

    $('btn').click(function () {

       alert('I am clicked !')

    }

}

Post a Comment

Thank you

Previous Post Next Post