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.
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
}
You can try:
declare var $: any;
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