ts-type-forge
    Preparing search index...
    MinLengthString: string & TSTypeForgeInternals_BrandEncapsulated<
        Readonly<{ MinLength: MinLengthTuple<MinLength, 0> }>,
    >

    Branded string type for strings with at least MinLength characters.

    The brand is encoded so that the natural subtyping relation between length constraints is preserved: if M >= N, then MinLengthString<M> is assignable to MinLengthString<N> (a string of at least M characters is also a string of at least N characters). This is achieved by branding with a readonly tuple type that requires at least MinLength elements, which becomes a narrower type as the constraint gets stricter.

    Type Parameters

    • MinLength extends SupportedLength

      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)