API reference@evolu/commonType › String

const String: createTypeOfType("String");

Defined in: packages/common/src/Type.ts:2880

A JavaScript string Type without additional constraints.

Use when empty strings and surrounding whitespace are valid domain values. If only empty strings are invalid, add an explicit minLength. If surrounding whitespace is invalid, use TrimmedString. If both are invalid, use NonEmptyTrimmedString, the recommended base for ordinary human-entered text.

Example

A bounded wire value for a protocol that explicitly permits an empty value and significant whitespace:

import {
  assertOk,
  assertType,
  String,
  maxLength,
  type Brand,
} from "@evolu/common";

const WireValue100 = maxLength(100)(String);
type WireValue100 = typeof WireValue100.Output;

assertType<string & Brand<"MaxLength100">, WireValue100>();
assertOk(WireValue100.fromUnknown(""), "");
assertOk(WireValue100.fromUnknown(" value "), " value ");