1

In an external .ts file I am adding a method to jquery like so:

$.fn.serializeObject = function () {
  //do stuff
  return stuff;
};

I would like to add this new method to the typescript definitions for jquery from within this file, rather than adding it to jquery.d.ts, in this way I will maintain this new method definition even if I update jquery and it's type definition file later.

Is this possible?

jackmott
  • 1,112
  • 8
  • 16
  • 3
    Sure, just add it to a separate definition file, that imports the definitions from jquery.d.ts, and adds your new method to the JQuery type. – Heretic Monkey Mar 23 '16 at 17:44
  • Surprisingly that works even if files point at jquery.d.ts and not my new file! Feel free to make that an answer, I will accept it. – jackmott Mar 23 '16 at 17:52
  • 1
    If you're using Visual Studio, I know it will pick up anything in any .d.ts files you have, referenced or not. – Heretic Monkey Mar 23 '16 at 17:54
  • That is convenient at the moment but seems like potentially bad! – jackmott Mar 23 '16 at 18:01
  • Possible duplicate of http://stackoverflow.com/questions/32948271/extend-interface-defined-in-d-ts-file – Shawn Mar 25 '16 at 02:28

0 Answers0