Improve TypeScript type for isNonEmptyString() and isNonEmptyStringAndNotWhitespace() (#200)

This commit is contained in:
Simon Podlipsky 2023-10-26 16:37:39 +02:00 committed by GitHub
parent f10e2caf3d
commit 0d4cf6fcc8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import type {
Class,
Falsy,
NodeStream,
NonEmptyString,
ObservableLike,
Predicate,
Primitive,
@ -582,12 +583,12 @@ export function isNonEmptySet<T = unknown>(value: unknown): value is Set<T> {
}
// 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);
}

View file

@ -73,3 +73,5 @@ export type NodeStream = {
} & NodeJS.EventEmitter;
export type Predicate = (value: unknown) => boolean;
export type NonEmptyString = string & {0: string};