Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Property does not exist on type JQueryStatic

I have written a jQuery plugin where I use jQuery's internal _data method. Which leads to the above compiler error.

(function ($) {     

var evts = $._data(document, 'events'); // internal method
....

Can I supress this error and how? What is the recommended way to approach this issue?

I know I could do the following:

$["_data"]

or

($ as any)._data

but I would prefer making a $._data a valid method call.

like image 834
Legends Avatar asked Mar 02 '17 16:03

Legends


2 Answers

but I would prefer making a $._data a valid method call.

The types intentionally don't allow internal API calls as the jquery team doesn't want you to use these methods. If you want to write unsafe code like this you are free to use $ as any as you have figured out.

If you want such unsafe access to be done safely you can extend the JQuery interface with new functionality

interface JQuery {
  _data: any; // Replace with your types
}
like image 105
basarat Avatar answered Oct 22 '22 00:10

basarat


You can try:

declare var $: any;
like image 1
Marlon Silva Avatar answered Oct 22 '22 01:10

Marlon Silva