Configure Typescript for Jquery
By default, jquery will not be recognized in typescript files you create. This means that any jquery code you use will show up as erroneous and you can't make use of the auto-complete functionality. However, this is easy enough to remedy as shown below.
Steps
Copy the typescript declaration file into your project from here. Unfortunately the download links do not appear to work so you have to manually copy/paste.
Place the content into a file called jquery.d.ts
in your project.
Add a relative path link to that file at the very top of your typescript files that require jquery. For example:
/// <reference path="../../jquery.d.ts" />
Backup File
If the link for the jquery.d.ts doesn't work, I grabbed a copy at the time of writing this article so you can grab it with the command below.
wget https://files.programster.org/tutorials/javascript/typescript/configure-typescript-for-jquery/jquery.d.ts
References
- Stack Overflow - How do I get jQuery autocompletion in TypeScript?
- Stack Overflow - Where can I get the latest typescript JQuery definition file from?
Last updated: 10th November 2021
First published: 16th August 2018
First published: 16th August 2018