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
}
你可以试试:
declare var $: any;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.