From 0d4cf6fcc89a558dd8ea4cf22819a8634b0742b7 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Thu, 26 Oct 2023 16:37:39 +0200 Subject: [PATCH] Improve TypeScript type for `isNonEmptyString()` and `isNonEmptyStringAndNotWhitespace()` (#200) --- source/index.ts | 5 +++-- source/types.ts | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/source/index.ts b/source/index.ts index 848af80..2ee08d3 100644 --- a/source/index.ts +++ b/source/index.ts @@ -4,6 +4,7 @@ import type { Class, Falsy, NodeStream, + NonEmptyString, ObservableLike, Predicate, Primitive, @@ -582,12 +583,12 @@ export function isNonEmptySet(value: unknown): value is Set { } // TODO: Use `not ''` when the `not` operator is available. -export function isNonEmptyString(value: unknown): value is string { +export function isNonEmptyString(value: unknown): value is NonEmptyString { return isString(value) && value.length > 0; } // TODO: Use `not ''` when the `not` operator is available. -export function isNonEmptyStringAndNotWhitespace(value: unknown): value is string { +export function isNonEmptyStringAndNotWhitespace(value: unknown): value is NonEmptyString { return isString(value) && !isEmptyStringOrWhitespace(value); } diff --git a/source/types.ts b/source/types.ts index 621c771..e77d73a 100644 --- a/source/types.ts +++ b/source/types.ts @@ -73,3 +73,5 @@ export type NodeStream = { } & NodeJS.EventEmitter; export type Predicate = (value: unknown) => boolean; + +export type NonEmptyString = string & {0: string};