Merge pull request #8730 from chrootsu/lodash-get

lodash: changed _.get
This commit is contained in:
Masahiro Wakame
2016-03-27 09:49:28 +09:00
4 changed files with 308 additions and 40 deletions
+83 -11
View File
@@ -8546,18 +8546,90 @@ namespace TestFunctions {
}
// _.get
result = <number>_.get<number>({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c');
namespace TestGet {
{
let result: string;
{
let result: TResult;
result = _.get<TResult>({}, '');
result = _.get<TResult>({}, 42);
result = _.get<TResult>({}, true);
result = _.get<TResult>({}, ['', 42, true]);
result = _({}).get<TResult>('');
result = _({}).get<TResult>(42);
result = _({}).get<TResult>(true);
result = _({}).get<TResult>(['', 42, true]);
result = _.get<string, string>('abc', '0');
result = _.get<string, string>('abc', '0', '_');
result = _.get<string, string>('abc', ['0']);
result = _.get<string, string>('abc', ['0'], '_');
result = _.get<string>('abc', '0');
result = _.get<string>('abc', '0', '_');
result = _.get<string>('abc', ['0']);
result = _.get<string>('abc', ['0'], '_');
result = _('abc').get<string>('0');
result = _('abc').get<string>('0', '_');
result = _('abc').get<string>(['0']);
result = _('abc').get<string>(['0'], '_');
}
{
let result: number;
result = _.get<number[], number>([42], '0');
result = _.get<number[], number>([42], '0', -1);
result = _.get<number[], number>([42], ['0']);
result = _.get<number[], number>([42], ['0'], -1);
result = _.get<number>([42], '0');
result = _.get<number>([42], '0', -1);
result = _.get<number>([42], ['0']);
result = _.get<number>([42], ['0'], -1);
result = _([42]).get<number>('0');
result = _([42]).get<number>('0', -1);
result = _([42]).get<number>(['0']);
result = _([42]).get<number>(['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<boolean>({a: true}, 'a');
result = _.get<boolean>({a: true}, 'a', false);
result = _.get<boolean>({a: true}, ['a']);
result = _.get<boolean>({a: true}, ['a'], false);
result = _({a: true}).get<boolean>('a');
result = _({a: true}).get<boolean>('a', false);
result = _({a: true}).get<boolean>(['a']);
result = _({a: true}).get<boolean>(['a'], false);
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>('0');
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>('0', '_');
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>(['0']);
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>(['0'], '_');
}
{
let result: _.LoDashExplicitWrapper<number>;
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>('0');
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>('0', -1);
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>(['0']);
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>(['0'], -1);
}
{
let result: _.LoDashExplicitWrapper<boolean>;
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>('a');
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>('a', false);
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>(['a']);
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>(['a'], false);
}
}
// _.has
+71 -9
View File
@@ -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<TResult>(object: Object,
path: string|number|boolean|Array<string|number|boolean>,
defaultValue?:TResult
*/
get<TObject, TResult>(
object: TObject,
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
/**
* @see _.get
*/
get<TResult>(
object: any,
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.get
*/
get<TResult>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.get
*/
get<TResult>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.get
**/
get<TResult>(path: string|number|boolean|Array<string|number|boolean>,
defaultValue?: TResult
*/
get<TResult>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.get
*/
get<TResultWrapper>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: any
): TResultWrapper;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.get
*/
get<TResultWrapper>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: any
): TResultWrapper;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.get
*/
get<TResultWrapper>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: any
): TResultWrapper;
}
//_.has
interface LoDashStatic {
/**
+83 -11
View File
@@ -9340,18 +9340,90 @@ namespace TestFunctionsIn {
}
// _.get
result = <number>_.get<number>({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c');
namespace TestGet {
{
let result: string;
{
let result: TResult;
result = _.get<TResult>({}, '');
result = _.get<TResult>({}, 42);
result = _.get<TResult>({}, true);
result = _.get<TResult>({}, ['', 42, true]);
result = _({}).get<TResult>('');
result = _({}).get<TResult>(42);
result = _({}).get<TResult>(true);
result = _({}).get<TResult>(['', 42, true]);
result = _.get<string, string>('abc', '0');
result = _.get<string, string>('abc', '0', '_');
result = _.get<string, string>('abc', ['0']);
result = _.get<string, string>('abc', ['0'], '_');
result = _.get<string>('abc', '0');
result = _.get<string>('abc', '0', '_');
result = _.get<string>('abc', ['0']);
result = _.get<string>('abc', ['0'], '_');
result = _('abc').get<string>('0');
result = _('abc').get<string>('0', '_');
result = _('abc').get<string>(['0']);
result = _('abc').get<string>(['0'], '_');
}
{
let result: number;
result = _.get<number[], number>([42], '0');
result = _.get<number[], number>([42], '0', -1);
result = _.get<number[], number>([42], ['0']);
result = _.get<number[], number>([42], ['0'], -1);
result = _.get<number>([42], '0');
result = _.get<number>([42], '0', -1);
result = _.get<number>([42], ['0']);
result = _.get<number>([42], ['0'], -1);
result = _([42]).get<number>('0');
result = _([42]).get<number>('0', -1);
result = _([42]).get<number>(['0']);
result = _([42]).get<number>(['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<boolean>({a: true}, 'a');
result = _.get<boolean>({a: true}, 'a', false);
result = _.get<boolean>({a: true}, ['a']);
result = _.get<boolean>({a: true}, ['a'], false);
result = _({a: true}).get<boolean>('a');
result = _({a: true}).get<boolean>('a', false);
result = _({a: true}).get<boolean>(['a']);
result = _({a: true}).get<boolean>(['a'], false);
}
{
let result: _.LoDashExplicitWrapper<string>;
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>('0');
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>('0', '_');
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>(['0']);
result = _('abc').chain().get<_.LoDashExplicitWrapper<string>>(['0'], '_');
}
{
let result: _.LoDashExplicitWrapper<number>;
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>('0');
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>('0', -1);
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>(['0']);
result = _([42]).chain().get<_.LoDashExplicitWrapper<number>>(['0'], -1);
}
{
let result: _.LoDashExplicitWrapper<boolean>;
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>('a');
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>('a', false);
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>(['a']);
result = _({a: true}).chain().get<_.LoDashExplicitWrapper<boolean>>(['a'], false);
}
}
// _.has
+71 -9
View File
@@ -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<TResult>(object: Object,
path: string|number|boolean|Array<string|number|boolean>,
defaultValue?:TResult
*/
get<TObject, TResult>(
object: TObject,
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
/**
* @see _.get
*/
get<TResult>(
object: any,
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashImplicitWrapper<T> {
/**
* @see _.get
*/
get<TResult>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashImplicitArrayWrapper<T> {
/**
* @see _.get
*/
get<TResult>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashImplicitObjectWrapper<T> {
/**
* @see _.get
**/
get<TResult>(path: string|number|boolean|Array<string|number|boolean>,
defaultValue?: TResult
*/
get<TResult>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: TResult
): TResult;
}
interface LoDashExplicitWrapper<T> {
/**
* @see _.get
*/
get<TResultWrapper>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: any
): TResultWrapper;
}
interface LoDashExplicitArrayWrapper<T> {
/**
* @see _.get
*/
get<TResultWrapper>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: any
): TResultWrapper;
}
interface LoDashExplicitObjectWrapper<T> {
/**
* @see _.get
*/
get<TResultWrapper>(
path: StringRepresentable|StringRepresentable[],
defaultValue?: any
): TResultWrapper;
}
//_.has
interface LoDashStatic {
/**