diff --git a/source/index.ts b/source/index.ts index be9f990..6deb8d0 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,11 +247,10 @@ 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; +is.falsy = (value: T | Falsy): value is Falsy => !value; is.nan = (value: unknown) => Number.isNaN(value as number); diff --git a/source/types.ts b/source/types.ts index 8bdd0f5..f6da50c 100644 --- a/source/types.ts +++ b/source/types.ts @@ -47,3 +47,5 @@ export interface ObservableLike { subscribe(observer: (value: unknown) => void): void; [Symbol.observable](): ObservableLike; } + +export type Falsy = false | 0 | 0n | '' | null | undefined;