tern
tern copied to clipboard
Overloaded jQuery getter/setters always use return type of getter
Some of the jQuery methods like attr, css, and prop, function as both getters and setters, and return different types for the getter vs. the setter.
It would be nice if tern could figure out the return type based on the number of arguments passed to the function, so the hints would be based on the correct type.
$("div").css("display", "none"). // hints are for string, instead of jQuery
Maybe some way to specify multiple signatures in the jquery.json file for these methods could work?
Also the methods height width html
Yes, this is a limitation of the default definition system -- it doesn't handle overloading. It's possible to write custom code to handle such functions, but that seems overkill for the jQuery module.
Overloading simply on the number of arguments would not be too hard to implement, I guess, and would come in handy often. I'll leave this issue open. Not sure when I'll get to it.
heya @marijnh, is this feature request still open? do you have any idea if there was any progress on this idea?
I think more and more that tern should support multiple signature https://github.com/ternjs/tern/issues/713
It could support this issue like TypeScript Definition support it https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/jquery/jquery.d.ts#L1406
css(propertyName: string): string;
/**
* Set one or more CSS properties for the set of matched elements.
*
* @param propertyName A CSS property name.
* @param value A value to set for the property.
*/
css(propertyName: string, value: string|number): JQuery;
/**
* Set one or more CSS properties for the set of matched elements.
*
* @param propertyName A CSS property name.
* @param value A function returning the value to set. this is the current element. Receives the index position of the element in the set and the old value as arguments.
*/
css(propertyName: string, value: (index: number, value: string) => string|number): JQuery;
/**
* Set one or more CSS properties for the set of matched elements.
*
* @param properties An object of property-value pairs to set.
*/
css(properties: Object): JQuery;