From 9af5cff974c12af1a36a7043c5fbb460a28ba532 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 14 May 2014 18:00:49 -0700 Subject: [PATCH 1/2] $.parseJSON should return `any` instead of `Object` Here is my test: ```js var i = JSON.parse('1'); var a = JSON.parse('[1]'); var o = JSON.parse('{"foo":"bar"}'); var s = JSON.parse('"string"'); var n = JSON.parse('null'); i instanceof Object; // false a instanceof Object; // true o instanceof Object; // true s instanceof Object; // false n instanceof Object; // false ``` JSON.parse returns the `any` type so I think this method should do the same. More of the discussion regarding this pull request can be found on the original commit 8c23d04a5b4a0505df042a82be90f95adff02d87 https://github.com/borisyankov/DefinitelyTyped/commit/8c23d04a5b4a0505df042a82be90f95adff02d87 --- jquery/jquery.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jquery/jquery.d.ts b/jquery/jquery.d.ts index b378dfd0a..70a9532ab 100644 --- a/jquery/jquery.d.ts +++ b/jquery/jquery.d.ts @@ -1214,7 +1214,7 @@ interface JQueryStatic { * * @param json The JSON string to parse. */ - parseJSON(json: string): Object; + parseJSON(json: string): any; /** * Parses a string into an XML document. From 575a77c92152f0500a1ac38ad952572b1d4229f1 Mon Sep 17 00:00:00 2001 From: Steven Salat Date: Thu, 15 May 2014 14:23:05 -0700 Subject: [PATCH 2/2] Added test for parseJSON --- jquery/jquery-tests.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/jquery/jquery-tests.ts b/jquery/jquery-tests.ts index 973818f5a..81ddb3ae1 100644 --- a/jquery/jquery-tests.ts +++ b/jquery/jquery-tests.ts @@ -3116,6 +3116,22 @@ function test_parseHTML() { .appendTo( $log ); } +// http://api.jquery.com/jQuery.parseJSON/ +function test_parseJSON() { + // Return type should be any, not Object + var i = $.parseJSON('1'); + var a = $.parseJSON('[1]'); + var o = $.parseJSON('{"foo":"bar"}'); + var s = $.parseJSON('"string"'); + var n = $.parseJSON('null'); + + i instanceof Object; // false + a instanceof Object; // true + o instanceof Object; // true + s instanceof Object; // false + n instanceof Object; // false +} + function test_not() { $("li").not(":even").css("background-color", "red");