mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Merge pull request #5467 from chrootsu/lodash-clone
lodash: changed _.clone() and _.cloneDeep() methods
This commit is contained in:
+81
-39
@@ -1097,41 +1097,89 @@ helloWrap2();
|
||||
* Lang *
|
||||
********/
|
||||
|
||||
// _.cloneDeep
|
||||
interface TestCloneDeepFn {
|
||||
// _.clone
|
||||
interface TestCloneCustomizerFn {
|
||||
(value: any): any;
|
||||
}
|
||||
var testCloneDeepFn: TestCloneDeepFn;
|
||||
result = <number>_.cloneDeep<number>(1);
|
||||
result = <number>_.cloneDeep<number>(1, testCloneDeepFn);
|
||||
result = <number>_.cloneDeep<number>(1, testCloneDeepFn, any);
|
||||
result = <string>_.cloneDeep<string>('a');
|
||||
result = <string>_.cloneDeep<string>('a', testCloneDeepFn);
|
||||
result = <string>_.cloneDeep<string>('a', testCloneDeepFn, any);
|
||||
result = <boolean>_.cloneDeep<boolean>(true);
|
||||
result = <boolean>_.cloneDeep<boolean>(true, testCloneDeepFn);
|
||||
result = <boolean>_.cloneDeep<boolean>(true, testCloneDeepFn, any);
|
||||
result = <number[]>_.cloneDeep<number[]>([1, 2]);
|
||||
result = <number[]>_.cloneDeep<number[]>([1, 2], testCloneDeepFn);
|
||||
result = <number[]>_.cloneDeep<number[]>([1, 2], testCloneDeepFn, any);
|
||||
result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}});
|
||||
result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepFn);
|
||||
result = <{a: {b: number;}}>_.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepFn, any);
|
||||
result = <number>_(1).cloneDeep();
|
||||
result = <number>_(1).cloneDeep(testCloneDeepFn);
|
||||
result = <number>_(1).cloneDeep(testCloneDeepFn, any);
|
||||
result = <string>_('a').cloneDeep();
|
||||
result = <string>_('a').cloneDeep(testCloneDeepFn);
|
||||
result = <string>_('a').cloneDeep(testCloneDeepFn, any);
|
||||
result = <boolean>_(true).cloneDeep();
|
||||
result = <boolean>_(true).cloneDeep(testCloneDeepFn);
|
||||
result = <boolean>_(true).cloneDeep(testCloneDeepFn, any);
|
||||
result = <number[]>_([1, 2]).cloneDeep();
|
||||
result = <number[]>_([1, 2]).cloneDeep(testCloneDeepFn);
|
||||
result = <number[]>_([1, 2]).cloneDeep(testCloneDeepFn, any);
|
||||
result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep();
|
||||
result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep(testCloneDeepFn);
|
||||
result = <{a: {b: number;}}>_({a: {b: 2}}).cloneDeep(testCloneDeepFn, any);
|
||||
var testCloneCustomizerFn: TestCloneCustomizerFn;
|
||||
{
|
||||
let result: number;
|
||||
result = _.clone<number>(42);
|
||||
result = _.clone<number>(42, false);
|
||||
result = _.clone<number>(42, false, testCloneCustomizerFn);
|
||||
result = _.clone<number>(42, false, testCloneCustomizerFn, any);
|
||||
result = _.clone<number>(42, testCloneCustomizerFn);
|
||||
result = _.clone<number>(42, testCloneCustomizerFn, any);
|
||||
result = _(42).clone();
|
||||
result = _(42).clone(false);
|
||||
result = _(42).clone(false, testCloneCustomizerFn);
|
||||
result = _(42).clone(false, testCloneCustomizerFn, any);
|
||||
result = _(42).clone(testCloneCustomizerFn);
|
||||
result = _(42).clone(testCloneCustomizerFn, any);
|
||||
}
|
||||
{
|
||||
let result: string[];
|
||||
result = _.clone<string[]>([]);
|
||||
result = _.clone<string[]>([], false);
|
||||
result = _.clone<string[]>([], false, testCloneCustomizerFn);
|
||||
result = _.clone<string[]>([], false, testCloneCustomizerFn, any);
|
||||
result = _.clone<string[]>([], testCloneCustomizerFn);
|
||||
result = _.clone<string[]>([], testCloneCustomizerFn, any);
|
||||
result = _<string>([]).clone();
|
||||
result = _<string>([]).clone(false);
|
||||
result = _<string>([]).clone(false, testCloneCustomizerFn);
|
||||
result = _<string>([]).clone(false, testCloneCustomizerFn, any);
|
||||
result = _<string>([]).clone(testCloneCustomizerFn);
|
||||
result = _<string>([]).clone(testCloneCustomizerFn, any);
|
||||
}
|
||||
{
|
||||
let result: {a: {b: number;}};
|
||||
result = _.clone<{a: {b: number;}}>({a: {b: 2}});
|
||||
result = _.clone<{a: {b: number;}}>({a: {b: 2}}, false);
|
||||
result = _.clone<{a: {b: number;}}>({a: {b: 2}}, false, testCloneCustomizerFn);
|
||||
result = _.clone<{a: {b: number;}}>({a: {b: 2}}, false, testCloneCustomizerFn, any);
|
||||
result = _.clone<{a: {b: number;}}>({a: {b: 2}}, testCloneCustomizerFn);
|
||||
result = _.clone<{a: {b: number;}}>({a: {b: 2}}, testCloneCustomizerFn, any);
|
||||
result = _({a: {b: 2}}).clone();
|
||||
result = _({a: {b: 2}}).clone(false);
|
||||
result = _({a: {b: 2}}).clone(false, testCloneCustomizerFn);
|
||||
result = _({a: {b: 2}}).clone(false, testCloneCustomizerFn, any);
|
||||
result = _({a: {b: 2}}).clone(testCloneCustomizerFn);
|
||||
result = _({a: {b: 2}}).clone(testCloneCustomizerFn, any);
|
||||
}
|
||||
|
||||
// _.cloneDeep
|
||||
interface TestCloneDeepCustomizerFn {
|
||||
(value: any): any;
|
||||
}
|
||||
var testCloneDeepCustomizerFn: TestCloneDeepCustomizerFn;
|
||||
{
|
||||
let result: number;
|
||||
result = _.cloneDeep<number>(42);
|
||||
result = _.cloneDeep<number>(42, testCloneDeepCustomizerFn);
|
||||
result = _.cloneDeep<number>(42, testCloneDeepCustomizerFn, any);
|
||||
result = _(42).cloneDeep();
|
||||
result = _(42).cloneDeep(testCloneDeepCustomizerFn);
|
||||
result = _(42).cloneDeep(testCloneDeepCustomizerFn, any);
|
||||
}
|
||||
{
|
||||
let result: string[];
|
||||
result = _.cloneDeep<string[]>([]);
|
||||
result = _.cloneDeep<string[]>([], testCloneDeepCustomizerFn);
|
||||
result = _.cloneDeep<string[]>([], testCloneDeepCustomizerFn, any);
|
||||
result = _<string>([]).cloneDeep();
|
||||
result = _<string>([]).cloneDeep(testCloneDeepCustomizerFn);
|
||||
result = _<string>([]).cloneDeep(testCloneDeepCustomizerFn, any);
|
||||
}
|
||||
{
|
||||
let result: {a: {b: number;}};
|
||||
result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}});
|
||||
result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepCustomizerFn);
|
||||
result = _.cloneDeep<{a: {b: number;}}>({a: {b: 2}}, testCloneDeepCustomizerFn, any);
|
||||
result = _({a: {b: 2}}).cloneDeep();
|
||||
result = _({a: {b: 2}}).cloneDeep(testCloneDeepCustomizerFn);
|
||||
result = _({a: {b: 2}}).cloneDeep(testCloneDeepCustomizerFn, any);
|
||||
}
|
||||
|
||||
// _.gt
|
||||
result = <boolean>_.gt(1, 2);
|
||||
@@ -1292,12 +1340,6 @@ result = <{}>_(testCreateProto).create(testCreateProps).value();
|
||||
result = <TestCreateProto>_(testCreateProto).create<TestCreateProto>().value();
|
||||
result = <TestCreateTResult>_(testCreateProto).create<TestCreateTResult>(testCreateProps).value();
|
||||
|
||||
result = <IStoogesAge[]>_.clone(stoogesAges);
|
||||
result = <IStoogesAge[]>_.clone(stoogesAges, true);
|
||||
result = <any>_.clone(stoogesAges, true, function (value) {
|
||||
return _.isElement(value) ? value.cloneNode(false) : undefined;
|
||||
});
|
||||
|
||||
interface Food {
|
||||
name: string;
|
||||
type: string;
|
||||
|
||||
Vendored
+87
-25
@@ -5997,6 +5997,88 @@ declare module _ {
|
||||
* Lang *
|
||||
********/
|
||||
|
||||
//_.clone
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a clone of value. If isDeep is true nested objects are cloned, otherwise they are assigned by
|
||||
* reference. If customizer is provided it’s invoked to produce the cloned values. If customizer returns
|
||||
* undefined cloning is handled by the method instead. The customizer is bound to thisArg and invoked with up
|
||||
* to three argument; (value [, index|key, object]).
|
||||
* Note: This method is loosely based on the structured clone algorithm. The enumerable properties of arguments
|
||||
* objects and objects created by constructors other than Object are cloned to plain Object objects. An empty
|
||||
* object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps.
|
||||
* @param value The value to clone.
|
||||
* @param isDeep Specify a deep clone.
|
||||
* @param customizer The function to customize cloning values.
|
||||
* @param thisArg The this binding of customizer.
|
||||
* @return Returns the cloned value.
|
||||
*/
|
||||
clone<T>(
|
||||
value: T,
|
||||
isDeep?: boolean,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
|
||||
/**
|
||||
* @see _.clone
|
||||
*/
|
||||
clone<T>(
|
||||
value: T,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
}
|
||||
|
||||
interface LoDashWrapper<T> {
|
||||
/**
|
||||
* @see _.clone
|
||||
*/
|
||||
clone(
|
||||
isDeep?: boolean,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
|
||||
/**
|
||||
* @see _.clone
|
||||
*/
|
||||
clone(
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
}
|
||||
|
||||
interface LoDashArrayWrapper<T> {
|
||||
/**
|
||||
* @see _.clone
|
||||
*/
|
||||
clone(
|
||||
isDeep?: boolean,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T[];
|
||||
|
||||
/**
|
||||
* @see _.clone
|
||||
*/
|
||||
clone(
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T[];
|
||||
}
|
||||
|
||||
interface LoDashObjectWrapper<T> {
|
||||
/**
|
||||
* @see _.clone
|
||||
*/
|
||||
clone(
|
||||
isDeep?: boolean,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
|
||||
/**
|
||||
* @see _.clone
|
||||
*/
|
||||
clone(
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
}
|
||||
|
||||
//_.cloneDeep
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
@@ -6007,13 +6089,13 @@ declare module _ {
|
||||
* objects and objects created by constructors other than Object are cloned to plain Object objects. An empty
|
||||
* object is returned for uncloneable values such as functions, DOM nodes, Maps, Sets, and WeakMaps.
|
||||
* @param value The value to deep clone.
|
||||
* @param callback The function to customize cloning values.
|
||||
* @param customizer The function to customize cloning values.
|
||||
* @param thisArg The this binding of customizer.
|
||||
* @return Returns the deep cloned value.
|
||||
*/
|
||||
cloneDeep<T>(
|
||||
value: T,
|
||||
callback?: (value: any) => any,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
}
|
||||
|
||||
@@ -6022,7 +6104,7 @@ declare module _ {
|
||||
* @see _.cloneDeep
|
||||
*/
|
||||
cloneDeep(
|
||||
callback?: (value: any) => any,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
}
|
||||
|
||||
@@ -6031,7 +6113,7 @@ declare module _ {
|
||||
* @see _.cloneDeep
|
||||
*/
|
||||
cloneDeep(
|
||||
callback?: (value: any) => any,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T[];
|
||||
}
|
||||
|
||||
@@ -6040,7 +6122,7 @@ declare module _ {
|
||||
* @see _.cloneDeep
|
||||
*/
|
||||
cloneDeep(
|
||||
callback?: (value: any) => any,
|
||||
customizer?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
}
|
||||
|
||||
@@ -6565,26 +6647,6 @@ declare module _ {
|
||||
create<TResult extends {}>(properties?: Object): LoDashObjectWrapper<TResult>;
|
||||
}
|
||||
|
||||
//_.clone
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
* Creates a clone of value. If deep is true nested objects will also be cloned, otherwise
|
||||
* they will be assigned by reference. If a callback is provided it will be executed to produce
|
||||
* the cloned values. If the callback returns undefined cloning will be handled by the method
|
||||
* instead. The callback is bound to thisArg and invoked with one argument; (value).
|
||||
* @param value The value to clone.
|
||||
* @param deep Specify a deep clone.
|
||||
* @param callback The function to customize cloning values.
|
||||
* @param thisArg The this binding of callback.
|
||||
* @return The cloned value.
|
||||
**/
|
||||
clone<T>(
|
||||
value: T,
|
||||
deep?: boolean,
|
||||
callback?: (value: any) => any,
|
||||
thisArg?: any): T;
|
||||
}
|
||||
|
||||
//_.defaults
|
||||
interface LoDashStatic {
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user