[@types/lodash] _.chain().get() shorthand for empty array default (#35497)

* _.chain().get() shorthand for empty array default

* add tests for lodash _.chain.get(x, []) shorthand

* linting fix & better fallback

* use explicit never[] type and add better test of chained _.get()

* use never[] in _.chain().get() fallback
This commit is contained in:
Andrew Schmadel 2019-05-20 12:02:32 -04:00 committed by Nathan Shively-Sanders
parent 08081f49e9
commit 49245ed7e4
2 changed files with 5 additions and 0 deletions

View File

@ -1122,6 +1122,10 @@ declare module "../index" {
* @see _.get
*/
get<TKey extends keyof T>(path: TKey | [TKey]): ExpChain<T[TKey]>;
/**
* @see _.get
*/
get<TKey extends keyof T>(path: TKey | [TKey], defaultValue: never[]): T[TKey] extends any[] ? ExpChain<Exclude<T[TKey], undefined>> : ExpChain<Exclude<T[TKey], undefined> | never[]>;
/**
* @see _.get
*/

View File

@ -5201,6 +5201,7 @@ fp.now(); // $ExpectType number
_.chain({ a: undefined }).get("a"); // $ExpectType never
_.chain({ a: value }).get("a", defaultValue); // $ExpectType StringChain | PrimitiveChain<false> | PrimitiveChain<true>
_.chain({ a: undefined }).get("a", defaultValue); // $ExpectType PrimitiveChain<false> | PrimitiveChain<true>
_.chain({ a: [1] }).get("a", []).map((val) => val.toFixed()); // $ExpectType CollectionChain<string>
fp.get(Symbol.iterator, []); // $ExpectType any
fp.get(Symbol.iterator)([]); // $ExpectType any