From cdca61035a709b4c022b91c52ac65061e29d43f2 Mon Sep 17 00:00:00 2001 From: Mike Dvorscak Date: Thu, 18 May 2017 11:40:32 -0500 Subject: [PATCH 1/4] Add JQueryCssProperties interface for $.css(properties: object) Adding JQueryCssProperties interface and changing the signature for $.css(properties: object) to $.css(properties: JQueryCssProperties) --- types/jquery/index.d.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index ca799f21e5..9dc1bf466e 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -679,6 +679,13 @@ interface JQueryCoordinates { top: number; } +/** + * The interface used to specify the properties parameter in css() + */ +interface JQueryCssProperties { + [propertyName: string]: string | number | Function; +} + /** * Elements in the array returned by serializeArray() */ @@ -1687,7 +1694,7 @@ interface JQuery { * @param properties An object of property-value pairs to set. * @see {@link https://api.jquery.com/css/#css-properties} */ - css(properties: Object): JQuery; + css(properties: JQueryCssProperties): JQuery; /** * Get the current computed height for the first element in the set of matched elements. From 9d2d217c3c929db64c59a9cf96b5b356e9c5bf95 Mon Sep 17 00:00:00 2001 From: Dvorscak Date: Fri, 2 Jun 2017 10:05:20 -0500 Subject: [PATCH 2/4] Add test for css function second parameter --- types/jquery/index.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 9dc1bf466e..39d75e1eaf 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -682,8 +682,9 @@ interface JQueryCoordinates { /** * The interface used to specify the properties parameter in css() */ +type cssPropertySetter = (index: number, value: string) => string | number; interface JQueryCssProperties { - [propertyName: string]: string | number | Function; + [propertyName: string]: string | number | cssPropertySetter; } /** From 5222e357223f7208a46098464d61cc4f4038300b Mon Sep 17 00:00:00 2001 From: Dvorscak Date: Fri, 2 Jun 2017 10:05:42 -0500 Subject: [PATCH 3/4] Make cssPropertySettter more strict --- types/jquery/jquery-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index d2d58aa2a2..3a2d2a74bc 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -1062,8 +1062,8 @@ function test_css() { var color = $(this).css("background-color"); $("#result").html("That div is " + color + "."); }); - $('div.example').css('width', function (index) { - return index * 50; + $('div.example').css('width', function (index, style) { + return style.length > 0 ? style : index * 50; }); $("p").mouseover(function () { $(this).css("color", "red"); From d6d2799379f556296eec72ba396506e14bb8e5da Mon Sep 17 00:00:00 2001 From: Dvorscak Date: Fri, 9 Jun 2017 15:39:57 -0500 Subject: [PATCH 4/4] Make second parameter optional --- types/jquery/index.d.ts | 2 +- types/jquery/jquery-tests.ts | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/types/jquery/index.d.ts b/types/jquery/index.d.ts index 39d75e1eaf..ccfc0c0f38 100644 --- a/types/jquery/index.d.ts +++ b/types/jquery/index.d.ts @@ -682,7 +682,7 @@ interface JQueryCoordinates { /** * The interface used to specify the properties parameter in css() */ -type cssPropertySetter = (index: number, value: string) => string | number; +type cssPropertySetter = (index: number, value?: string) => string | number; interface JQueryCssProperties { [propertyName: string]: string | number | cssPropertySetter; } diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 3a2d2a74bc..4b6fc4e0db 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -1062,6 +1062,9 @@ function test_css() { var color = $(this).css("background-color"); $("#result").html("That div is " + color + "."); }); + $('div.example').css('width', function (index) { + return index * 50; + }); $('div.example').css('width', function (index, style) { return style.length > 0 ? style : index * 50; });