ts-type-forge
    Preparing search index...
    FixedLengthString: BoundedLengthString<Length, Length>

    Branded string type for strings with exactly Length characters. Alias for BoundedLengthString<Length, Length>.

    Type Parameters

    • Length extends SupportedLength

      The exact number of characters. Must be a non-negative integer literal.

    const countryCode = 'JP' as FixedLengthString<2>;

    const atMost5: MaxLengthString<5> = countryCode; // OK (2 <= 5)
    const nonEmpty: MinLengthString<1> = countryCode; // OK (2 >= 1)
    // const threeChars: FixedLengthString<3> = countryCode; // Error!