Merge pull request #33228 from OliverJAsh/oja/lodash-is-object-type-guard

Lodash: `isObject`: user-defined type guard
This commit is contained in:
Nathan Shively-Sanders
2019-03-11 15:33:07 -07:00
committed by GitHub
3 changed files with 9 additions and 3 deletions

View File

@@ -1224,14 +1224,14 @@ 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<TValue> {
/**
* see _.isObject
*/
isObject(): boolean;
isObject(): this is LoDashImplicitWrapper<object>;
}
interface LoDashExplicitWrapper<TValue> {

View File

@@ -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;

View File

@@ -4291,6 +4291,12 @@ fp.now(); // $ExpectType number
_(42).isObject(); // $ExpectType boolean
_.chain([]).isObject(); // $ExpectType LoDashExplicitWrapper<boolean>
fp.isObject(anything); // $ExpectType boolean
if (fp.isObject(anything)) {
anything; // $ExpectType object
}
if (_.isObject(anything)) {
anything; // $ExpectType object
}
}
// _.isObjectLike