add type guard for is.truthy to narrow result
This commit is contained in:
parent
f5cc764e22
commit
12a61619d0
2 changed files with 4 additions and 3 deletions
|
|
@ -2,7 +2,7 @@
|
|||
/// <reference lib="dom"/>
|
||||
/// <reference types="node"/>
|
||||
|
||||
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 = <T>(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;
|
||||
|
||||
|
|
|
|||
|
|
@ -47,3 +47,5 @@ export interface ObservableLike {
|
|||
subscribe(observer: (value: unknown) => void): void;
|
||||
[Symbol.observable](): ObservableLike;
|
||||
}
|
||||
|
||||
export type Falsy = false | 0 | 0n | '' | null | undefined;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue