From 7c924f2efe4cf7c461c4991e3581dc018fcdfa98 Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sun, 14 Feb 2016 20:42:03 +0500 Subject: [PATCH] lodash: changed _.result --- lodash/lodash-3.10-tests.ts | 116 +++++++++++++++++++++++++++++++++--- lodash/lodash-3.10.d.ts | 71 ++++++++++++++++++++-- lodash/lodash-tests.ts | 116 +++++++++++++++++++++++++++++++++--- lodash/lodash.d.ts | 71 ++++++++++++++++++++-- 4 files changed, 346 insertions(+), 28 deletions(-) diff --git a/lodash/lodash-3.10-tests.ts b/lodash/lodash-3.10-tests.ts index c4048bb26..fddb4a936 100644 --- a/lodash/lodash-3.10-tests.ts +++ b/lodash/lodash-3.10-tests.ts @@ -8985,14 +8985,114 @@ namespace TestPick { } // _.result -{ - let testResultPath: number|string|boolean|Array; - let testResultDefaultValue: TResult; - let result: TResult; - result = _.result<{}, TResult>({}, testResultPath); - result = _.result<{}, TResult>({}, testResultPath, testResultDefaultValue); - result = _({}).result(testResultPath); - result = _({}).result(testResultPath, testResultDefaultValue); +namespace TestResult { + { + let result: string; + + result = _.result('abc', '0'); + result = _.result('abc', '0', '_'); + result = _.result('abc', '0', () => '_'); + result = _.result('abc', ['0']); + result = _.result('abc', ['0'], '_'); + result = _.result('abc', ['0'], () => '_'); + + result = _.result('abc', '0'); + result = _.result('abc', '0', '_'); + result = _.result('abc', '0', () => '_'); + result = _.result('abc', ['0']); + result = _.result('abc', ['0'], '_'); + result = _.result('abc', ['0'], () => '_'); + + result = _('abc').result('0'); + result = _('abc').result('0', '_'); + result = _('abc').result('0', () => '_'); + result = _('abc').result(['0']); + result = _('abc').result(['0'], '_'); + result = _('abc').result(['0'], () => '_'); + } + + { + let result: number; + + result = _.result([42], '0'); + result = _.result([42], '0', -1); + result = _.result([42], '0', () => -1); + result = _.result([42], ['0']); + result = _.result([42], ['0'], -1); + result = _.result([42], ['0'], () => -1); + + result = _.result([42], '0'); + result = _.result([42], '0', -1); + result = _.result([42], '0', () => -1); + result = _.result([42], ['0']); + result = _.result([42], ['0'], -1); + result = _.result([42], ['0'], () => -1); + + result = _([42]).result('0'); + result = _([42]).result('0', -1); + result = _([42]).result('0', () => -1); + result = _([42]).result(['0']); + result = _([42]).result(['0'], -1); + result = _([42]).result(['0'], () => -1); + } + + { + let result: boolean; + + result = _.result<{a: boolean}, boolean>({a: true}, 'a'); + result = _.result<{a: boolean}, boolean>({a: true}, 'a', false); + result = _.result<{a: boolean}, boolean>({a: true}, 'a', () => false); + result = _.result<{a: boolean}, boolean>({a: true}, ['a']); + result = _.result<{a: boolean}, boolean>({a: true}, ['a'], false); + result = _.result<{a: boolean}, boolean>({a: true}, ['a'], () => false); + + result = _.result({a: true}, 'a'); + result = _.result({a: true}, 'a', false); + result = _.result({a: true}, 'a', () => false); + result = _.result({a: true}, ['a']); + result = _.result({a: true}, ['a'], false); + result = _.result({a: true}, ['a'], () => false); + + result = _({a: true}).result('a'); + result = _({a: true}).result('a', false); + result = _({a: true}).result('a', () => false); + result = _({a: true}).result(['a']); + result = _({a: true}).result(['a'], false); + result = _({a: true}).result(['a'], () => false); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('abc').chain().result<_.LoDashExplicitWrapper>('0'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>('0', '_'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>('0', '_'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>(['0']); + result = _('abc').chain().result<_.LoDashExplicitWrapper>(['0'], () => '_'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>(['0'], () => '_'); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _([42]).chain().result<_.LoDashExplicitWrapper>('0'); + result = _([42]).chain().result<_.LoDashExplicitWrapper>('0', -1); + result = _([42]).chain().result<_.LoDashExplicitWrapper>('0', () => -1); + result = _([42]).chain().result<_.LoDashExplicitWrapper>(['0']); + result = _([42]).chain().result<_.LoDashExplicitWrapper>(['0'], -1); + result = _([42]).chain().result<_.LoDashExplicitWrapper>(['0'], () => -1); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>('a'); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>('a', false); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>('a', () => false); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>(['a']); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>(['a'], false); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>(['a'], () => false); + } } // _.set diff --git a/lodash/lodash-3.10.d.ts b/lodash/lodash-3.10.d.ts index c673e0300..d33178346 100644 --- a/lodash/lodash-3.10.d.ts +++ b/lodash/lodash-3.10.d.ts @@ -13833,21 +13833,80 @@ declare module _ { */ result( object: TObject, - path: number|string|boolean|Array, - defaultValue?: TResult + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) ): TResult; - } - interface LoDashImplicitWrapperBase { /** * @see _.result */ result( - path: number|string|boolean|Array, - defaultValue?: TResult + object: any, + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) ): TResult; } + interface LoDashImplicitWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) + ): TResult; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) + ): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) + ): TResult; + } + + interface LoDashExplicitWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + //_.set interface LoDashStatic { /** diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 0f739288a..790b266bc 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -9901,14 +9901,114 @@ namespace TestPickBy { } // _.result -{ - let testResultPath: number|string|boolean|Array; - let testResultDefaultValue: TResult; - let result: TResult; - result = _.result<{}, TResult>({}, testResultPath); - result = _.result<{}, TResult>({}, testResultPath, testResultDefaultValue); - result = _({}).result(testResultPath); - result = _({}).result(testResultPath, testResultDefaultValue); +namespace TestResult { + { + let result: string; + + result = _.result('abc', '0'); + result = _.result('abc', '0', '_'); + result = _.result('abc', '0', () => '_'); + result = _.result('abc', ['0']); + result = _.result('abc', ['0'], '_'); + result = _.result('abc', ['0'], () => '_'); + + result = _.result('abc', '0'); + result = _.result('abc', '0', '_'); + result = _.result('abc', '0', () => '_'); + result = _.result('abc', ['0']); + result = _.result('abc', ['0'], '_'); + result = _.result('abc', ['0'], () => '_'); + + result = _('abc').result('0'); + result = _('abc').result('0', '_'); + result = _('abc').result('0', () => '_'); + result = _('abc').result(['0']); + result = _('abc').result(['0'], '_'); + result = _('abc').result(['0'], () => '_'); + } + + { + let result: number; + + result = _.result([42], '0'); + result = _.result([42], '0', -1); + result = _.result([42], '0', () => -1); + result = _.result([42], ['0']); + result = _.result([42], ['0'], -1); + result = _.result([42], ['0'], () => -1); + + result = _.result([42], '0'); + result = _.result([42], '0', -1); + result = _.result([42], '0', () => -1); + result = _.result([42], ['0']); + result = _.result([42], ['0'], -1); + result = _.result([42], ['0'], () => -1); + + result = _([42]).result('0'); + result = _([42]).result('0', -1); + result = _([42]).result('0', () => -1); + result = _([42]).result(['0']); + result = _([42]).result(['0'], -1); + result = _([42]).result(['0'], () => -1); + } + + { + let result: boolean; + + result = _.result<{a: boolean}, boolean>({a: true}, 'a'); + result = _.result<{a: boolean}, boolean>({a: true}, 'a', false); + result = _.result<{a: boolean}, boolean>({a: true}, 'a', () => false); + result = _.result<{a: boolean}, boolean>({a: true}, ['a']); + result = _.result<{a: boolean}, boolean>({a: true}, ['a'], false); + result = _.result<{a: boolean}, boolean>({a: true}, ['a'], () => false); + + result = _.result({a: true}, 'a'); + result = _.result({a: true}, 'a', false); + result = _.result({a: true}, 'a', () => false); + result = _.result({a: true}, ['a']); + result = _.result({a: true}, ['a'], false); + result = _.result({a: true}, ['a'], () => false); + + result = _({a: true}).result('a'); + result = _({a: true}).result('a', false); + result = _({a: true}).result('a', () => false); + result = _({a: true}).result(['a']); + result = _({a: true}).result(['a'], false); + result = _({a: true}).result(['a'], () => false); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('abc').chain().result<_.LoDashExplicitWrapper>('0'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>('0', '_'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>('0', '_'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>(['0']); + result = _('abc').chain().result<_.LoDashExplicitWrapper>(['0'], () => '_'); + result = _('abc').chain().result<_.LoDashExplicitWrapper>(['0'], () => '_'); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _([42]).chain().result<_.LoDashExplicitWrapper>('0'); + result = _([42]).chain().result<_.LoDashExplicitWrapper>('0', -1); + result = _([42]).chain().result<_.LoDashExplicitWrapper>('0', () => -1); + result = _([42]).chain().result<_.LoDashExplicitWrapper>(['0']); + result = _([42]).chain().result<_.LoDashExplicitWrapper>(['0'], -1); + result = _([42]).chain().result<_.LoDashExplicitWrapper>(['0'], () => -1); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>('a'); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>('a', false); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>('a', () => false); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>(['a']); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>(['a'], false); + result = _({a: true}).chain().result<_.LoDashExplicitWrapper>(['a'], () => false); + } } // _.set diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 86bd909de..56a475b95 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -16522,21 +16522,80 @@ declare module _ { */ result( object: TObject, - path: number|string|boolean|Array, - defaultValue?: TResult + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) ): TResult; - } - interface LoDashImplicitWrapperBase { /** * @see _.result */ result( - path: number|string|boolean|Array, - defaultValue?: TResult + object: any, + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) ): TResult; } + interface LoDashImplicitWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) + ): TResult; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) + ): TResult; + } + + interface LoDashImplicitObjectWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult|((...args: any[]) => TResult) + ): TResult; + } + + interface LoDashExplicitWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.result + */ + result( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + //_.set interface LoDashStatic { /**