true if minLength <= s.length && s.length <= maxLength, false
otherwise. When true, TypeScript narrows s to
BoundedLengthString<MinLength, MaxLength> & S.
const input: string = 'user-12345678';
assert.isTrue(isBoundedLengthString(input, 8, 16));
assert.isFalse(isBoundedLengthString('user', 8, 16));
if (isBoundedLengthString(input, 8, 16)) {
const userId: BoundedLengthString<8, 16> = input;
const relaxed: BoundedLengthString<1, 255> = input; // OK ([8, 16] ⊆ [1, 255])
}
Type guard that checks if a string's length is within the inclusive range
[minLength, maxLength].The length is measured in UTF-16 code units (the same unit as
String.prototype.length), so characters outside the Basic Multilingual Plane (e.g. emoji) count as 2.Type Narrowing Behavior:
BoundedLengthString<MinLength, MaxLength>while preserving the original string type (e.g. literal types) via intersection.BoundedLengthStringis the intersection ofMinLengthStringandMaxLengthString, the narrowed value is assignable to both, and both bounds can be weakened independently.