From 3be19b29f014e474430d1cb4687762cc57b93852 Mon Sep 17 00:00:00 2001 From: Eric Amodio Date: Mon, 23 Sep 2019 22:31:55 -0400 Subject: [PATCH] Expands `is` usability --- src/system/function.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/system/function.ts b/src/system/function.ts index c5f8166..cb00d1a 100644 --- a/src/system/function.ts +++ b/src/system/function.ts @@ -111,16 +111,16 @@ export namespace Functions { : []; } + export function is(o: T | null | undefined): o is T; export function is(o: object, prop: keyof T, value?: any): o is T; export function is(o: object, matcher: (o: object) => boolean): o is T; export function is( o: object, - propOrMatcher: keyof T | ((o: any) => boolean), + propOrMatcher?: keyof T | ((o: any) => boolean), value?: any ): o is T { - if (typeof propOrMatcher === 'function') { - return propOrMatcher(o); - } + if (propOrMatcher == null) return o != null; + if (typeof propOrMatcher === 'function') return propOrMatcher(o); return value === undefined ? (o as any)[propOrMatcher] !== undefined : (o as any)[propOrMatcher] === value; }