Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8621627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:51:43+00:00 2026-06-12T06:51:43+00:00

When using typescript do I need to import a plugin.d.ts for every external js

  • 0

When using typescript do I need to import a plugin.d.ts for every external js that I use?
In other words, do I need to create a jQuery.d.ts with all the interfaces?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T06:51:44+00:00Added an answer on June 12, 2026 at 6:51 am

    The issue with jQuery plugins (and other plugin based libraries) is that not only do you need a library.d.ts file for the base library, but you also need a plugin.d.ts file for each plugin. And somehow thes plugin.d.ts files need to extend the library interfaces defined in the library.d.ts files. Fortunately, TypeScript has a nifty little feature that lets you do just that.

    With classes there currently can only be a single cononical definition of a class within a project. So if you define a class Foo the members you put on Foo are all you get. Any additional definitions of Foo will result in an error. With interfaces, however, the members are additive so if you define interface Bar with a set of members you can define ‘interface Bar’ a second time to add additional members to the interface. That’s the key to supporting jQuery plugins in a strongly typed way.

    So to add support for a given jQuery plugin you’re going to need to create a plugin.d.ts file for the plugin you want to use. We use jQuery Templates in our project so here’s the jquery.tmpl.d.ts file we created to add support for that plugin:

    interface JQuery
    {
        tmpl(data?:any,options?:any): JQuery;
        tmplItem(): JQueryTmplItem;
        template(name?:string): ()=>any;
    }
    
    interface JQueryStatic
    {
        tmpl(template:string,data?:any,options?:any): JQuery;
        tmpl(template:(data:any)=>string,data?:any,options?:any): JQuery;
        tmplItem(element:JQuery): JQueryTmplItem;
        tmplItem(element:HTMLElement): JQueryTmplItem;
        template(name:string,template:any): (data:any)=>string[];
        template(template:any): JQueryTemplateDelegate;
    }
    
    interface JQueryTemplateDelegate {
        (jQuery: JQueryStatic, data: any):string[];
    }
    
    interface JQueryTmplItem
    {
        data:any;
        nodes:HTMLElement[];
        key:number;
        parent:JQueryTmplItem;
    }
    

    Breaking this down the first thing we did is to define the methods that get added to the JQuery interface. These let you get intellisense and type checking when you type $('#foo').tmpl(); Next we added methods to the JQueryStatic interface which show up when you type $.tmpl(); And finally the jQuery Templates plugin defines some of its own data structures so we needed to define interfaces for those structures.

    Now that we have the additional interfaces definied we just need to reference them from the consuming .ts files. To do that we just add the references below to the top of our .ts file and that’s it. For that file, TypeScript will see both the base jQuery methods and the plugin methods. If you use multiple plugins just make sure you refernce all of your individual plugin.d.ts files and you should be good.

    /// <reference path="jquery.d.ts"/>
    /// <reference path="jquery.tmpl.d.ts" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using a binary search tree I need to add to a vector all int
Using C#, I need a class called User that has a username, password, active
I'm just starting to use QUnit and having issues. I'm currently using TypeScript, which
When using the TypeScript plugin for vs.net, how do I make one TypeScript file
Using the Redis info command, I am able to get all the stats of
Using import datetime in python, is it possible to take a formatted time/date string
We all may know the following snippet that gets the first entry of the
Assume the following class definition using TypeScript in Animal.ts: module Animals { export class
Installing a rails plugin using the git:// protocol is easy, you just type script/plugin
Using php/html, I want to retrieve email addresses (plus other information) from MySQL and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.