-
Notifications
You must be signed in to change notification settings - Fork 264
jQuery.parseJSON: Function has multiple return types, not just Object. #490
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
jQuery.parseJSON: Function has multiple return types, not just Object. #490
Conversation
I'm not sure what you're proposing to change it to. Object is correct. |
I fixed the stray line break in the example. It's being deployed right now. |
@scottgonzalez I'm suggesting that (Also, thanks for the quick fix to the other minor issue--seems you are in lightning deploy mode. :) |
Sorry about that; your original wording was extremely confusing about what you were trying to change. Your edit makes it much more obvious. A PR to list the multiple types would be great. |
@scottgonzalez Yeah, sorry if it was confusing before. I was just a little taken aback by the close-first-ask-questions-later reaction. Though I guess it keeps the queue clear. :] Speaking of questions, I have a few before I attach a pull request:
Thanks! |
Yeah, the quick close is to keep the list clean. As you've seen, we're just as quick to reopen upon clarification :-)
|
Re: 1., I see Re: 2., Ok, I'll add Re: 3, Done. |
Also formats "malformed JSON strings" examples to appear as actual strings, and adds a few more invalid cases to the list. Closes jquery#490
Preliminary work at usmonster/api.jquery.com@77b81d0. Haven't yet added any new examples, nor any note on the fact that any returned |
Just FYI if you're looking for consistent type signatures for jQuery APIs the TypeScript at https://github.com/borisyankov/DefinitelyTyped/tree/master/jquery might be handy. |
Cool, thanks for the link. It looks like it could be useful if we wanted to find and fix all the inconsistencies between the documented and actual API, though "virtual types" used in the docs would still need to be checked. Also, I suppose we'd often want to document "intended use" even/especially when the code itself doesn't check or otherwise enforce some of the input types (e.g. jquery/api.jqueryui.com#202). For now, I'm happy just filling in gaps as I come across them. :] My current internal conflict over
Though in the end, I know it's extremely pedantic, and I'm not sure many people will actually care about the distinction.. :] In any case, I'm going to attach my pull request in its current state, and someone else can make an executive decision as to what else to do, if anything. |
Well, you care, and we care about you. 👪 But seriously, the folks who run the DefinitelyTyped repo have paged me for a few questions and often it relates to some ambiguity with the args. I'd like to be able to point to the docs and say "that's not valid input" when people try passing junk. OTOH I don't want to get so pedantic about the return types that we end up with dozens of them with minor differences. So for now I'd pass on I'm okay with this PR as-is, the extra examples are nice. I was a bit concerned about having so many return values, the closest we have is http://api.jquery.com/val/ , but it seems the design doesn't explode on small screens when there are that many. |
Aw shucks. You guys. :]
Good to merge as-is, then? Bit confused about the help wanted tag. |
<li><code>"{test: 1}"</code> (test does not have double quotes around it).</li> | ||
<li><code>"{'test': 1}"</code> ('test' is using single quotes instead of double quotes).</li> | ||
<li><code>"'test'"</code> ('test' is using single quotes instead of double quotes).</li> | ||
<li><code>".1"</code> (a numbers must start with a digit; <code>"0.1"</code> would be valid).</li> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be either "a number" or "numbers"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, updated PR.
@gnarf, my point was more that the documentation implies that the |
@kswedberg, just a ping to let you know that I think all concerns about this PR have been addressed, so feel free to merge if you agree or to comment if you don't. |
Anything left to do on this? @scottgonzalez @dmethvin |
LGTM |
thanks, @usmonster! Sorry it took so long to merge this in. |
The return type is currently documented as
Object
, with the description "...returns the resulting JavaScript object."As this function is roughly equivalent to
JSON.parse
, it technically produces an ECMAScript value, which, in addition toObject
(or, really,PlainObject
), can also includeString
,Number
,Array
,Boolean
, ornull
. These multiple return types should be explicitly mentioned on the return type.Shall I attach a PR to make this change and update the description? To further clarify, perhaps another example could be added? (Related, minor issue: There's a rogue line break towards the end of the current example...)