Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overloaded jQuery getter/setters always use return type of getter #123

Open
eztierney opened this issue May 9, 2013 · 4 comments
Open

Comments

@eztierney
Copy link
Contributor

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?

@eztierney
Copy link
Contributor Author

Also the methods
height
width
html

@marijnh
Copy link
Member

marijnh commented May 10, 2013

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.

@eyalse
Copy link

eyalse commented Jun 27, 2016

heya @marijnh, is this feature request still open? do you have any idea if there was any progress on this idea?

@angelozerr
Copy link
Contributor

I think more and more that tern should support multiple signature #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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants