I have a site with 10 pages, which share a Typescript file, and also each page has its own specific Typescript file. One page has a JQuery plugin, timepicker
, so I extend the JQuery object using:
interface JQuery {
timepicker(options:any):JQuery;
}
However I don't want any of the other TypeScript files to have timepicker on the JQuery
object. How can I extend it just for this file?
It doesn't let me extend JQuery
inside a namespace.
Can modules help? I have no need to import or export anything, so I am not sure it is appropriate, or how to use modules.
You could name the interface something more reflective of what it is—something like:
interface JQueryWithTimePicker extends JQuery {
timepicker(options: any): JQuery;
}
Then your one file that needs the timepicker can use the JQuery object downcast to JQueryWithTimePicker.
I use this strategy sometimes when I need to add properties to DOM nodes. Something like:
interface MyTreeElement extends HTMLElement
{
Nodes: TreeNode[];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With