Type guard that checks if a value is a non-empty string.
This function performs both a type check (ensuring the value is a string) and
a length check (ensuring the string is not empty). It acts as a type guard
that narrows the input type to exclude null, undefined, and empty
strings.
Type Narrowing Behavior:
Eliminates null and undefined from the type
Excludes empty string ("") from the type
Preserves literal string types when possible
Whitespace-only strings are considered non-empty
Type Parameters
Sextendsstring|null|undefined
The input type, which can include string, null, or
undefined
Type guard that checks if a value is a non-empty string.
This function performs both a type check (ensuring the value is a string) and a length check (ensuring the string is not empty). It acts as a type guard that narrows the input type to exclude
null
,undefined
, and empty strings.Type Narrowing Behavior:
null
andundefined
from the type""
) from the type