diff --git a/source/index.ts b/source/index.ts index be9f990..34148f5 100644 --- a/source/index.ts +++ b/source/index.ts @@ -2,7 +2,7 @@ /// /// -import {Class, TypedArray, ObservableLike, Primitive} from './types'; +import {Class, Falsy, TypedArray, ObservableLike, Primitive} from './types'; const typedArrayTypeNames = [ 'Int8Array', @@ -247,9 +247,8 @@ is.urlString = (value: unknown): value is string => { } }; -// TODO: Use the `not` operator with a type guard here when it's available. // Example: `is.truthy = (value: unknown): value is (not false | not 0 | not '' | not undefined | not null) => Boolean(value);` -is.truthy = (value: unknown) => Boolean(value); +is.truthy = (value: T | Falsy): value is T => Boolean(value); // Example: `is.falsy = (value: unknown): value is (not true | 0 | '' | undefined | null) => Boolean(value);` is.falsy = (value: unknown) => !value; diff --git a/source/types.ts b/source/types.ts index 8bdd0f5..ad38e33 100644 --- a/source/types.ts +++ b/source/types.ts @@ -47,3 +47,6 @@ export interface ObservableLike { subscribe(observer: (value: unknown) => void): void; [Symbol.observable](): ObservableLike; } + + +export type Falsy = false | 0 | '' | null | undefined