From 94c04275d26b070d06109fe3c5f0ce19f184ed2c Mon Sep 17 00:00:00 2001 From: Ilya Mochalov Date: Sat, 13 Feb 2016 21:17:33 +0500 Subject: [PATCH] lodash: changed _.get --- lodash/lodash-3.10-tests.ts | 94 ++++++++++++++++++++++++++++++++----- lodash/lodash-3.10.d.ts | 80 +++++++++++++++++++++++++++---- lodash/lodash-tests.ts | 94 ++++++++++++++++++++++++++++++++----- lodash/lodash.d.ts | 80 +++++++++++++++++++++++++++---- 4 files changed, 308 insertions(+), 40 deletions(-) diff --git a/lodash/lodash-3.10-tests.ts b/lodash/lodash-3.10-tests.ts index c4048bb26..fa8ca2144 100644 --- a/lodash/lodash-3.10-tests.ts +++ b/lodash/lodash-3.10-tests.ts @@ -8546,18 +8546,90 @@ namespace TestFunctions { } // _.get -result = _.get({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c'); +namespace TestGet { + { + let result: string; -{ - let result: TResult; - result = _.get({}, ''); - result = _.get({}, 42); - result = _.get({}, true); - result = _.get({}, ['', 42, true]); - result = _({}).get(''); - result = _({}).get(42); - result = _({}).get(true); - result = _({}).get(['', 42, true]); + result = _.get('abc', '0'); + result = _.get('abc', '0', '_'); + result = _.get('abc', ['0']); + result = _.get('abc', ['0'], '_'); + + result = _.get('abc', '0'); + result = _.get('abc', '0', '_'); + result = _.get('abc', ['0']); + result = _.get('abc', ['0'], '_'); + + result = _('abc').get('0'); + result = _('abc').get('0', '_'); + result = _('abc').get(['0']); + result = _('abc').get(['0'], '_'); + } + + { + let result: number; + + result = _.get([42], '0'); + result = _.get([42], '0', -1); + result = _.get([42], ['0']); + result = _.get([42], ['0'], -1); + + result = _.get([42], '0'); + result = _.get([42], '0', -1); + result = _.get([42], ['0']); + result = _.get([42], ['0'], -1); + + result = _([42]).get('0'); + result = _([42]).get('0', -1); + result = _([42]).get(['0']); + result = _([42]).get(['0'], -1); + } + + { + let result: boolean; + + result = _.get<{a: boolean}, boolean>({a: true}, 'a'); + result = _.get<{a: boolean}, boolean>({a: true}, 'a', false); + result = _.get<{a: boolean}, boolean>({a: true}, ['a']); + result = _.get<{a: boolean}, boolean>({a: true}, ['a'], false); + + result = _.get({a: true}, 'a'); + result = _.get({a: true}, 'a', false); + result = _.get({a: true}, ['a']); + result = _.get({a: true}, ['a'], false); + + result = _({a: true}).get('a'); + result = _({a: true}).get('a', false); + result = _({a: true}).get(['a']); + result = _({a: true}).get(['a'], false); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('abc').chain().get<_.LoDashExplicitWrapper>('0'); + result = _('abc').chain().get<_.LoDashExplicitWrapper>('0', '_'); + result = _('abc').chain().get<_.LoDashExplicitWrapper>(['0']); + result = _('abc').chain().get<_.LoDashExplicitWrapper>(['0'], '_'); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _([42]).chain().get<_.LoDashExplicitWrapper>('0'); + result = _([42]).chain().get<_.LoDashExplicitWrapper>('0', -1); + result = _([42]).chain().get<_.LoDashExplicitWrapper>(['0']); + result = _([42]).chain().get<_.LoDashExplicitWrapper>(['0'], -1); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>('a'); + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>('a', false); + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>(['a']); + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>(['a'], false); + } } // _.has diff --git a/lodash/lodash-3.10.d.ts b/lodash/lodash-3.10.d.ts index c673e0300..ff94488a0 100644 --- a/lodash/lodash-3.10.d.ts +++ b/lodash/lodash-3.10.d.ts @@ -13181,28 +13181,90 @@ declare module _ { //_.get interface LoDashStatic { /** - * Gets the property value at path of object. If the resolved - * value is undefined the defaultValue is used in its place. + * Gets the property value at path of object. If the resolved value is undefined the defaultValue is used + * in its place. + * * @param object The object to query. * @param path The path of the property to get. * @param defaultValue The value returned if the resolved value is undefined. * @return Returns the resolved value. - **/ - get(object: Object, - path: string|number|boolean|Array, - defaultValue?:TResult + */ + get( + object: TObject, + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult + ): TResult; + + /** + * @see _.get + */ + get( + object: any, + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult + ): TResult; + } + + interface LoDashImplicitWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult + ): TResult; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult ): TResult; } interface LoDashImplicitObjectWrapper { /** * @see _.get - **/ - get(path: string|number|boolean|Array, - defaultValue?: TResult + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult ): TResult; } + interface LoDashExplicitWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + //_.has interface LoDashStatic { /** diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index 0f739288a..3bbce009d 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -9340,18 +9340,90 @@ namespace TestFunctionsIn { } // _.get -result = _.get({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c'); +namespace TestGet { + { + let result: string; -{ - let result: TResult; - result = _.get({}, ''); - result = _.get({}, 42); - result = _.get({}, true); - result = _.get({}, ['', 42, true]); - result = _({}).get(''); - result = _({}).get(42); - result = _({}).get(true); - result = _({}).get(['', 42, true]); + result = _.get('abc', '0'); + result = _.get('abc', '0', '_'); + result = _.get('abc', ['0']); + result = _.get('abc', ['0'], '_'); + + result = _.get('abc', '0'); + result = _.get('abc', '0', '_'); + result = _.get('abc', ['0']); + result = _.get('abc', ['0'], '_'); + + result = _('abc').get('0'); + result = _('abc').get('0', '_'); + result = _('abc').get(['0']); + result = _('abc').get(['0'], '_'); + } + + { + let result: number; + + result = _.get([42], '0'); + result = _.get([42], '0', -1); + result = _.get([42], ['0']); + result = _.get([42], ['0'], -1); + + result = _.get([42], '0'); + result = _.get([42], '0', -1); + result = _.get([42], ['0']); + result = _.get([42], ['0'], -1); + + result = _([42]).get('0'); + result = _([42]).get('0', -1); + result = _([42]).get(['0']); + result = _([42]).get(['0'], -1); + } + + { + let result: boolean; + + result = _.get<{a: boolean}, boolean>({a: true}, 'a'); + result = _.get<{a: boolean}, boolean>({a: true}, 'a', false); + result = _.get<{a: boolean}, boolean>({a: true}, ['a']); + result = _.get<{a: boolean}, boolean>({a: true}, ['a'], false); + + result = _.get({a: true}, 'a'); + result = _.get({a: true}, 'a', false); + result = _.get({a: true}, ['a']); + result = _.get({a: true}, ['a'], false); + + result = _({a: true}).get('a'); + result = _({a: true}).get('a', false); + result = _({a: true}).get(['a']); + result = _({a: true}).get(['a'], false); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _('abc').chain().get<_.LoDashExplicitWrapper>('0'); + result = _('abc').chain().get<_.LoDashExplicitWrapper>('0', '_'); + result = _('abc').chain().get<_.LoDashExplicitWrapper>(['0']); + result = _('abc').chain().get<_.LoDashExplicitWrapper>(['0'], '_'); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _([42]).chain().get<_.LoDashExplicitWrapper>('0'); + result = _([42]).chain().get<_.LoDashExplicitWrapper>('0', -1); + result = _([42]).chain().get<_.LoDashExplicitWrapper>(['0']); + result = _([42]).chain().get<_.LoDashExplicitWrapper>(['0'], -1); + } + + { + let result: _.LoDashExplicitWrapper; + + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>('a'); + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>('a', false); + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>(['a']); + result = _({a: true}).chain().get<_.LoDashExplicitWrapper>(['a'], false); + } } // _.has diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 86bd909de..a81f69462 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -15502,28 +15502,90 @@ declare module _ { //_.get interface LoDashStatic { /** - * Gets the property value at path of object. If the resolved - * value is undefined the defaultValue is used in its place. + * Gets the property value at path of object. If the resolved value is undefined the defaultValue is used + * in its place. + * * @param object The object to query. * @param path The path of the property to get. * @param defaultValue The value returned if the resolved value is undefined. * @return Returns the resolved value. - **/ - get(object: Object, - path: string|number|boolean|Array, - defaultValue?:TResult + */ + get( + object: TObject, + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult + ): TResult; + + /** + * @see _.get + */ + get( + object: any, + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult + ): TResult; + } + + interface LoDashImplicitWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult + ): TResult; + } + + interface LoDashImplicitArrayWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult ): TResult; } interface LoDashImplicitObjectWrapper { /** * @see _.get - **/ - get(path: string|number|boolean|Array, - defaultValue?: TResult + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: TResult ): TResult; } + interface LoDashExplicitWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitArrayWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + + interface LoDashExplicitObjectWrapper { + /** + * @see _.get + */ + get( + path: StringRepresentable|StringRepresentable[], + defaultValue?: any + ): TResultWrapper; + } + //_.has interface LoDashStatic { /**