The minimum number of characters (inclusive). Must be a non-negative integer literal.
const isMinLengthString = <N extends SupportedLength>(
s: string,
minLength: N,
): s is MinLengthString<N> => s.length >= minLength;
const password = 'very-secret-password' as MinLengthString<12>;
const nonEmpty: MinLengthString<1> = password; // OK (12 >= 1)
// const longer: MinLengthString<16> = password; // Error! (12 < 16)
Branded string type for strings with at least
MinLengthcharacters.The brand is encoded so that the natural subtyping relation between length constraints is preserved: if
M >= N, thenMinLengthString<M>is assignable toMinLengthString<N>(a string of at leastMcharacters is also a string of at leastNcharacters). This is achieved by branding with a readonly tuple type that requires at leastMinLengthelements, which becomes a narrower type as the constraint gets stricter.