1

I have added a jQuery plugin that I have created into a TypeScript file. For instance, let's say I have this:

Extensions.ts

(function ($)
{
    $.fn.isNot = function (selector)
    {
        return !this.is(selector);
    };
}(jQuery));

function HelloWorld()
{
}

Then, in another file: enter image description here

As you can see, Utilities.ts can see the HelloWorld function but it cannot see the jQuery extensions...

However, when I try to reference this file by other files, it does not work. Is there a way of going about this so that I can create extension files like this in TypeScript and be able to reference them with other typescript files? Or will I have to create definition files for each of my extension files?

1 Answer 1

1

You can create a single definition file or one for each of your extensions - it is up to you.

It would be something like this:

interface JQuery {
  isNot(selector: string): boolean
}

This should be in a .d.ts file, in addition to the .ts code file

Sign up to request clarification or add additional context in comments.

8 Comments

Okay - so then for extension methods, I always need to have a definition file but if its a normal function I don't?
If you import the file with the function then no. If you want to use external libraries, or create one yourself - definition files are a must
What do you mean by import the file with a function? It is not an external library - it is an extension that i have written myself in a .ts file -
Great, then ignore the rest of my answer.. it isn't necessary in your case
But it's not working - even though my files reference my extension files they aren't able to actually use it...
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.