diff --git a/types/lodash/ts3.1/common/common.d.ts b/types/lodash/ts3.1/common/common.d.ts index 6b701d7f22..cec617312e 100644 --- a/types/lodash/ts3.1/common/common.d.ts +++ b/types/lodash/ts3.1/common/common.d.ts @@ -7,7 +7,7 @@ declare module "../index" { type Many = T | ReadonlyArray; type ImpChain = T extends { __trapAny: any } ? Collection & Function & Object & Primitive & String : - T extends null | undefined ? Primitive : + T extends null | undefined ? never : T extends string | null | undefined ? String : T extends (...args: any) => any ? Function : T extends List | null | undefined ? Collection : @@ -15,7 +15,7 @@ declare module "../index" { Primitive; type ExpChain = T extends { __trapAny: any } ? CollectionChain & FunctionChain & ObjectChain & PrimitiveChain & StringChain : - T extends null | undefined ? PrimitiveChain : + T extends null | undefined ? never : T extends string ? StringChain : T extends string | null | undefined ? StringNullableChain : T extends (...args: any) => any ? FunctionChain : diff --git a/types/lodash/ts3.1/lodash-tests.ts b/types/lodash/ts3.1/lodash-tests.ts index 88d8628718..c33673be5c 100644 --- a/types/lodash/ts3.1/lodash-tests.ts +++ b/types/lodash/ts3.1/lodash-tests.ts @@ -33,9 +33,9 @@ _([1, 2, 3, 4]).splice(1); // $ExpectType Collection _([1, 2, 3, 4]).splice(1, 2, 5, 6); // $ExpectType Collection _([1, 2, 3, 4]).unshift(5, 6); // $ExpectType Collection -_.chain([1, 2, 3, 4]).pop(); // $ExpectType PrimitiveChain | PrimitiveChain +_.chain([1, 2, 3, 4]).pop(); // $ExpectType PrimitiveChain _.chain([1, 2, 3, 4]).push(5, 6, 7); // $ExpectType CollectionChain -_.chain([1, 2, 3, 4]).shift(); // $ExpectType PrimitiveChain | PrimitiveChain +_.chain([1, 2, 3, 4]).shift(); // $ExpectType PrimitiveChain _.chain([1, 2, 3, 4]).sort((a, b) => 1); // $ExpectType CollectionChain _.chain([1, 2, 3, 4]).splice(1); // $ExpectType CollectionChain _.chain([1, 2, 3, 4]).splice(1, 2, 5, 6); // $ExpectType CollectionChain @@ -460,7 +460,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _(list).first(); // $ExpectType AbcObject | undefined _.chain("abc").first(); // $ExpectType StringNullableChain - _.chain(list).first(); // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).first(); // $ExpectType ObjectChain fp.first("abc"); // $ExpectType string | undefined fp.first(list); // $ExpectType AbcObject | undefined @@ -530,7 +530,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _(list).head(); // $ExpectType AbcObject | undefined _.chain("abc").head(); // $ExpectType StringNullableChain - _.chain(list).head(); // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).head(); // $ExpectType ObjectChain fp.head("abc"); // $ExpectType string | undefined fp.head(list); // $ExpectType AbcObject | undefined @@ -773,7 +773,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _(list).last(); // $ExpectType AbcObject | undefined _.chain("abc").last(); // $ExpectType StringNullableChain - _.chain(list).last(); // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).last(); // $ExpectType ObjectChain fp.last("abc"); // $ExpectType string | undefined fp.last(list); // $ExpectType AbcObject | undefined @@ -783,7 +783,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain { _.nth(list, 42); // $ExpectType AbcObject | undefined _(list).nth(42); // $ExpectType AbcObject | undefined - _.chain(list).nth(42); // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).nth(42); // $ExpectType ObjectChain fp.nth(42, list); // $ExpectType AbcObject | undefined fp.nth(42)(list); // $ExpectType AbcObject | undefined @@ -1821,19 +1821,19 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _(dictionary).find(["a", 5]); // $ExpectType AbcObject | undefined _([anything as AbcObject, null, undefined]).find((value: AbcObject | null | undefined): value is AbcObject | undefined => value !== null); // $ExpectType AbcObject | undefined - _.chain(list).find(); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).find(listIterator); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).find(listIterator, 1); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).find("a"); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).find({ a: 42 }); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).find(["a", 5]); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).find(); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).find(dictionaryIterator); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).find(dictionaryIterator, 1); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).find(""); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).find({ a: 42 }); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).find(["a", 5]); // $ExpectType PrimitiveChain | ObjectChain - // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).find(); // $ExpectType ObjectChain + _.chain(list).find(listIterator); // $ExpectType ObjectChain + _.chain(list).find(listIterator, 1); // $ExpectType ObjectChain + _.chain(list).find("a"); // $ExpectType ObjectChain + _.chain(list).find({ a: 42 }); // $ExpectType ObjectChain + _.chain(list).find(["a", 5]); // $ExpectType ObjectChain + _.chain(dictionary).find(); // $ExpectType ObjectChain + _.chain(dictionary).find(dictionaryIterator); // $ExpectType ObjectChain + _.chain(dictionary).find(dictionaryIterator, 1); // $ExpectType ObjectChain + _.chain(dictionary).find(""); // $ExpectType ObjectChain + _.chain(dictionary).find({ a: 42 }); // $ExpectType ObjectChain + _.chain(dictionary).find(["a", 5]); // $ExpectType ObjectChain + // $ExpectType ObjectChain _.chain([anything as AbcObject, null, undefined]).find((value: AbcObject | null | undefined): value is AbcObject | undefined => value !== null); fp.find(valueIterator, list); // $ExpectType AbcObject | undefined @@ -1880,19 +1880,19 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _(dictionary).findLast(["a", 5]); // $ExpectType AbcObject | undefined _([anything as AbcObject, null, undefined]).findLast((value: AbcObject | null | undefined): value is AbcObject | undefined => value !== null); // $ExpectType AbcObject | undefined - _.chain(list).findLast(); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).findLast(listIterator); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).findLast(listIterator, 1); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).findLast("a"); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).findLast({ a: 42 }); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).findLast(["a", 5]); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).findLast(); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).findLast(dictionaryIterator); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).findLast(dictionaryIterator, 1); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).findLast(""); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).findLast({ a: 42 }); // $ExpectType PrimitiveChain | ObjectChain - _.chain(dictionary).findLast(["a", 5]); // $ExpectType PrimitiveChain | ObjectChain - // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).findLast(); // $ExpectType ObjectChain + _.chain(list).findLast(listIterator); // $ExpectType ObjectChain + _.chain(list).findLast(listIterator, 1); // $ExpectType ObjectChain + _.chain(list).findLast("a"); // $ExpectType ObjectChain + _.chain(list).findLast({ a: 42 }); // $ExpectType ObjectChain + _.chain(list).findLast(["a", 5]); // $ExpectType ObjectChain + _.chain(dictionary).findLast(); // $ExpectType ObjectChain + _.chain(dictionary).findLast(dictionaryIterator); // $ExpectType ObjectChain + _.chain(dictionary).findLast(dictionaryIterator, 1); // $ExpectType ObjectChain + _.chain(dictionary).findLast(""); // $ExpectType ObjectChain + _.chain(dictionary).findLast({ a: 42 }); // $ExpectType ObjectChain + _.chain(dictionary).findLast(["a", 5]); // $ExpectType ObjectChain + // $ExpectType ObjectChain _.chain([anything as AbcObject, null, undefined]).findLast((value: AbcObject | null | undefined): value is AbcObject | undefined => value !== null); fp.findLast(valueIterator, list); // $ExpectType AbcObject | undefined @@ -2886,7 +2886,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _([1, 2, 3]).reduce((sum, num) => sum + num); // $ExpectType number | undefined _({ a: 1, b: 2, c: 3 }).reduce((r: ABC, num: number, key: string) => r, initial); // $ExpectType ABC - _.chain([1, 2, 3]).reduce((sum, num) => sum + num); // $ExpectType PrimitiveChain | PrimitiveChain + _.chain([1, 2, 3]).reduce((sum, num) => sum + num); // $ExpectType PrimitiveChain _.chain({ a: 1, b: 2, c: 3 }).reduce((r: ABC, num: number, key: string) => r, initial); // $ExpectType ObjectChain fp.reduce((s: string, num: number) => s + num, "", [1, 2, 3]); // $ExpectType string @@ -2899,7 +2899,7 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _([1, 2, 3]).reduceRight((sum, num) => sum + num); // $ExpectType number | undefined _({ a: 1, b: 2, c: 3 }).reduceRight((r: ABC, num: number, key: string) => r, initial); // $ExpectType ABC - _.chain([1, 2, 3]).reduceRight((sum, num) => sum + num); // $ExpectType PrimitiveChain | PrimitiveChain + _.chain([1, 2, 3]).reduceRight((sum, num) => sum + num); // $ExpectType PrimitiveChain _.chain({ a: 1, b: 2, c: 3 }).reduceRight((r: ABC, num: number, key: string) => r, initial); // $ExpectType ObjectChain fp.reduceRight((num: number, s: string) => s + num, "", [1, 2, 3]); // $ExpectType string @@ -2962,10 +2962,10 @@ _.chain([1, 2, 3, 4]).unshift(5, 6); // $ExpectType CollectionChain _({ a: "foo" }).sample(); // $ExpectType string | undefined _.chain("abc").sample(); // $ExpectType StringNullableChain - _.chain(list).sample(); // $ExpectType StringChain | PrimitiveChain - _.chain(dictionary).sample(); // $ExpectType StringChain | PrimitiveChain - _.chain(numericDictionary).sample(); // $ExpectType StringChain | PrimitiveChain - _.chain({ a: "foo" }).sample(); // $ExpectType StringChain | PrimitiveChain + _.chain(list).sample(); // $ExpectType StringChain + _.chain(dictionary).sample(); // $ExpectType StringChain + _.chain(numericDictionary).sample(); // $ExpectType StringChain + _.chain({ a: "foo" }).sample(); // $ExpectType StringChain fp.sample("abc"); // $ExpectType string | undefined fp.sample(list); // $ExpectType string | undefined @@ -4673,12 +4673,12 @@ fp.now(); // $ExpectType number _.max(list); // $ExpectType string | undefined _(list).max(); // $ExpectType string | undefined - _.chain(list).max(); // $ExpectType StringChain | PrimitiveChain + _.chain(list).max(); // $ExpectType StringChain fp.max(list); // $ExpectType string | undefined _.min(list); // $ExpectType string | undefined _(list).min(); // $ExpectType string | undefined - _.chain(list).min(); // $ExpectType StringChain | PrimitiveChain + _.chain(list).min(); // $ExpectType StringChain fp.min(list); // $ExpectType string | undefined } @@ -4693,9 +4693,9 @@ fp.now(); // $ExpectType number _(list).maxBy(valueIterator); // $ExpectType AbcObject | undefined _(list).maxBy("a"); // $ExpectType AbcObject | undefined _(list).maxBy({ a: 42 }); // $ExpectType AbcObject | undefined - _.chain(list).maxBy(valueIterator); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).maxBy("a"); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).maxBy({ a: 42 }); // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).maxBy(valueIterator); // $ExpectType ObjectChain + _.chain(list).maxBy("a"); // $ExpectType ObjectChain + _.chain(list).maxBy({ a: 42 }); // $ExpectType ObjectChain fp.maxBy(valueIterator)(list); // $ExpectType AbcObject | undefined fp.maxBy("a", list); // $ExpectType AbcObject | undefined fp.maxBy({ a: 42 }, list); // $ExpectType AbcObject | undefined @@ -4706,9 +4706,9 @@ fp.now(); // $ExpectType number _(list).minBy(valueIterator); // $ExpectType AbcObject | undefined _(list).minBy("a"); // $ExpectType AbcObject | undefined _(list).minBy({ a: 42 }); // $ExpectType AbcObject | undefined - _.chain(list).minBy(valueIterator); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).minBy("a"); // $ExpectType PrimitiveChain | ObjectChain - _.chain(list).minBy({ a: 42 }); // $ExpectType PrimitiveChain | ObjectChain + _.chain(list).minBy(valueIterator); // $ExpectType ObjectChain + _.chain(list).minBy("a"); // $ExpectType ObjectChain + _.chain(list).minBy({ a: 42 }); // $ExpectType ObjectChain fp.minBy(valueIterator)(list); // $ExpectType AbcObject | undefined fp.minBy("a", list); // $ExpectType AbcObject | undefined fp.minBy({ a: 42 }, list); // $ExpectType AbcObject | undefined @@ -5198,7 +5198,7 @@ fp.now(); // $ExpectType number _.chain({ a: { b: true } }).get("a"); // $ExpectType ObjectChain<{ b: boolean; }> _.chain({ a: { b: true } }).get(["a"]); // $ExpectType ObjectChain<{ b: boolean; }> _.chain({ a: { b: true } }).get(["a", "b"]); // $ExpectType LoDashExplicitWrapper - _.chain({ a: undefined }).get("a"); // $ExpectType PrimitiveChain + _.chain({ a: undefined }).get("a"); // $ExpectType never _.chain({ a: value }).get("a", defaultValue); // $ExpectType StringChain | PrimitiveChain | PrimitiveChain _.chain({ a: undefined }).get("a", defaultValue); // $ExpectType PrimitiveChain | PrimitiveChain diff --git a/types/lowdb/lowdb-tests.ts b/types/lowdb/lowdb-tests.ts index f47f1b627a..03ee6e0d60 100644 --- a/types/lowdb/lowdb-tests.ts +++ b/types/lowdb/lowdb-tests.ts @@ -17,7 +17,7 @@ const result: ArrayLike = db .push({ title: "hello", views: 123 }) .value(); -// $ExpectType Post | undefined +// $ExpectType Post db.get("posts") .find({ id: 123 }) .value(); @@ -27,10 +27,10 @@ db.get("posts") .write(); low(adapterAsync).then(dbAsync => { - const writeAction: Promise = (dbAsync + const writeAction: Promise = dbAsync .get("posts") .push({ title: "async hello" }) - .last() as _.ObjectChain) + .last() .assign({ id: Date.now().toString() }) .write(); @@ -44,9 +44,9 @@ low(adapterAsync).then(dbAsync => { .find({}) .value(); - const tuple: ArrayLike & Promise> = (dbAsync + const tuple: ArrayLike & Promise> = dbAsync .get("posts") - .first() as _.ObjectChain) + .first() .get("tuple") .write(); });