From 59b32e53531ac19bee174b8b019ea96e34be4f31 Mon Sep 17 00:00:00 2001 From: Leonard Thieu Date: Mon, 22 Oct 2018 12:25:28 -0400 Subject: [PATCH] [jquery] Add self-extending overloads of `jQuery.extend()`. (#29924) --- types/jquery/JQueryStatic.d.ts | 16 ++++++++++++++++ types/jquery/jquery-tests.ts | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/types/jquery/JQueryStatic.d.ts b/types/jquery/JQueryStatic.d.ts index 8e753d1739..64cbe6f47b 100644 --- a/types/jquery/JQueryStatic.d.ts +++ b/types/jquery/JQueryStatic.d.ts @@ -940,6 +940,14 @@ $( "#log" ).append( JSON.stringify( object1 ) ); ``` */ extend(deep: true, target: T, object1: U): T & U; + /** + * Merge the contents of two or more objects together into the first object. + * @param deep If true, the merge becomes recursive (aka. deep copy). Passing false for this argument is not supported. + * @param target The object to extend. It will receive the new properties. + * @see \`{@link https://api.jquery.com/jQuery.extend/ }\` + * @since 1.1.4 + */ + extend(deep: true, target: T): this & T; /** * Merge the contents of two or more objects together into the first object. * @param deep If true, the merge becomes recursive (aka. deep copy). Passing false for this argument is not supported. @@ -1431,6 +1439,14 @@ $( "#log" ).append( "
settings -- " + JSON.stringify( settings ) + "< ``` */ extend(target: T, object1: U): T & U; + /** + * Merge the contents of two or more objects together into the first object. + * @param target An object that will receive the new properties if additional objects are passed in or that will + * extend the jQuery namespace if it is the sole argument. + * @see \`{@link https://api.jquery.com/jQuery.extend/ }\` + * @since 1.0 + */ + extend(target: T): this & T; /** * Merge the contents of two or more objects together into the first object. * @param target An object that will receive the new properties if additional objects are passed in or that will diff --git a/types/jquery/jquery-tests.ts b/types/jquery/jquery-tests.ts index 548c20c10b..befd31e7e7 100644 --- a/types/jquery/jquery-tests.ts +++ b/types/jquery/jquery-tests.ts @@ -463,6 +463,9 @@ function JQueryStatic() { // $ExpectType { name: string; } & EventTarget $.extend(true, t, u); + // $ExpectType JQueryStatic & { name: string; } + $.extend(true, t); + // $ExpectType any $.extend(true, t, u, v, w, x, y, z, a); @@ -484,6 +487,9 @@ function JQueryStatic() { // $ExpectType { name: string; } & EventTarget $.extend(t, u); + // $ExpectType JQueryStatic & { name: string; } + $.extend(t); + // $ExpectType any $.extend(t, u, v, w, x, y, z, a); }