From efbf4f4d1dd5338f4a04877d40ccc0fba46f7ff5 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Wed, 20 Feb 2019 12:21:34 +0000 Subject: [PATCH 1/9] Lodash: `isObject`: user-defined type guard --- types/lodash/fp.d.ts | 2 +- types/lodash/lodash-tests.ts | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/types/lodash/fp.d.ts b/types/lodash/fp.d.ts index 68084f1c8d..c2c983ca6e 100644 --- a/types/lodash/fp.d.ts +++ b/types/lodash/fp.d.ts @@ -1984,7 +1984,7 @@ declare namespace _ { type LodashIsNil = (value: any) => value is null | undefined; type LodashIsNull = (value: any) => value is null; type LodashIsNumber = (value: any) => value is number; - type LodashIsObject = (value: any) => boolean; + type LodashIsObject = (value: any) => value is object; type LodashIsObjectLike = (value: any) => boolean; type LodashIsPlainObject = (value: any) => boolean; type LodashIsRegExp = (value: any) => value is RegExp; diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index 64d445c65a..b3b5910401 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -4291,6 +4291,10 @@ fp.now(); // $ExpectType number _(42).isObject(); // $ExpectType boolean _.chain([]).isObject(); // $ExpectType LoDashExplicitWrapper fp.isObject(anything); // $ExpectType boolean + if (fp.isObject(anything)) { + // $ExpectType object + anything + }; } // _.isObjectLike From 1603c4f4a8de0142d0d7b5be9f98f983cd8cea11 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Wed, 20 Feb 2019 12:41:56 +0000 Subject: [PATCH 2/9] Format --- types/lodash/lodash-tests.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index b3b5910401..fa5c0ad439 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -4293,8 +4293,8 @@ fp.now(); // $ExpectType number fp.isObject(anything); // $ExpectType boolean if (fp.isObject(anything)) { // $ExpectType object - anything - }; + anything; + } } // _.isObjectLike From 39de9c1f8407279e80cdaadde5b44a10a0186283 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Mon, 25 Feb 2019 08:35:45 +0000 Subject: [PATCH 3/9] Fix style nit --- types/lodash/lodash-tests.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index fa5c0ad439..f3089b4289 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -4292,8 +4292,7 @@ fp.now(); // $ExpectType number _.chain([]).isObject(); // $ExpectType LoDashExplicitWrapper fp.isObject(anything); // $ExpectType boolean if (fp.isObject(anything)) { - // $ExpectType object - anything; + anything; // $ExpectType object } } From c8b56a0ca413a0bb6991dbbfc9bcb2c5eec6d2ce Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Mon, 25 Feb 2019 08:40:29 +0000 Subject: [PATCH 4/9] Update source, not compiled --- types/lodash/common/lang.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/lodash/common/lang.d.ts b/types/lodash/common/lang.d.ts index 723388c9cc..cbfe0e56bb 100644 --- a/types/lodash/common/lang.d.ts +++ b/types/lodash/common/lang.d.ts @@ -1224,7 +1224,7 @@ declare module "../index" { * @param value The value to check. * @return Returns true if value is an object, else false. */ - isObject(value?: any): boolean; + isObject(value?: any): value is object; } interface LoDashImplicitWrapper { From 21ca8c60dde00b71b711b88147a20e56ec23da56 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Mon, 25 Feb 2019 08:40:37 +0000 Subject: [PATCH 5/9] Add remaining tests --- types/lodash/lodash-tests.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index f3089b4289..bef3f510f3 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -4294,6 +4294,15 @@ fp.now(); // $ExpectType number if (fp.isObject(anything)) { anything; // $ExpectType object } + if (_.isObject(anything)) { + anything; // $ExpectType object + } + if (_(anything).isObject()) { + anything; // $ExpectType any + } + if (_.chain(anything).isObject()) { + anything; // $ExpectType any + } } // _.isObjectLike From f108386f078f6777f9022d4d56f05d8cf1be2f7f Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Mon, 25 Feb 2019 12:14:57 +0000 Subject: [PATCH 6/9] Fix tests --- types/lodash/lodash-tests.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index bef3f510f3..9435ab16da 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -4300,7 +4300,7 @@ fp.now(); // $ExpectType number if (_(anything).isObject()) { anything; // $ExpectType any } - if (_.chain(anything).isObject()) { + if (_.chain(anything).isObject().value()) { anything; // $ExpectType any } } From 8318525edb8ddb232f0f309c8107536dd71ff3e5 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Mon, 25 Feb 2019 12:15:24 +0000 Subject: [PATCH 7/9] Apply to implicit wrapper --- types/lodash/common/lang.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/lodash/common/lang.d.ts b/types/lodash/common/lang.d.ts index cbfe0e56bb..14b00747a0 100644 --- a/types/lodash/common/lang.d.ts +++ b/types/lodash/common/lang.d.ts @@ -1231,7 +1231,7 @@ declare module "../index" { /** * see _.isObject */ - isObject(): boolean; + isObject(): this is LoDashImplicitWrapper; } interface LoDashExplicitWrapper { From ee2c0d0d07561ebede56ae0b43e7ad4d0a30a524 Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Mon, 25 Feb 2019 12:45:58 +0000 Subject: [PATCH 8/9] Remove redundant tests --- types/lodash/lodash-tests.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/types/lodash/lodash-tests.ts b/types/lodash/lodash-tests.ts index 9435ab16da..05c1a20215 100644 --- a/types/lodash/lodash-tests.ts +++ b/types/lodash/lodash-tests.ts @@ -4297,12 +4297,6 @@ fp.now(); // $ExpectType number if (_.isObject(anything)) { anything; // $ExpectType object } - if (_(anything).isObject()) { - anything; // $ExpectType any - } - if (_.chain(anything).isObject().value()) { - anything; // $ExpectType any - } } // _.isObjectLike From 246c3ed34bd24c811e2b4b02fc9e9db62445b92e Mon Sep 17 00:00:00 2001 From: Oliver Joseph Ash Date: Mon, 4 Mar 2019 10:57:08 +0000 Subject: [PATCH 9/9] Attempt to fix adone build errors Re. https://github.com/DefinitelyTyped/DefinitelyTyped/pull/33228#issuecomment-469030749 --- types/adone/tslint.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/types/adone/tslint.json b/types/adone/tslint.json index 8c265eebb4..2a9ae5c804 100644 --- a/types/adone/tslint.json +++ b/types/adone/tslint.json @@ -13,6 +13,7 @@ "no-unnecessary-qualifier": false, "unified-signatures": false, "space-before-function-paren": false, - "await-promise": false + "await-promise": false, + "no-restricted-globals": false } } \ No newline at end of file