StringThe string type with optional validation checks.
Details
checks holds string-specific constraints, such as min/max length, pattern,
and UUID checks. contentMediaType and contentSchema indicate that the
string contains encoded data, such as "application/json" with a nested
schema.
export interface String {
readonly String._tag: "String"_tag: "String"
readonly String.annotations?: Schema.Annotations.Annotations | undefinedannotations?: import SchemaSchema.Annotations.interface Annotations.AnnotationsThis interface is used to define the annotations that can be attached to a
schema. You can extend this interface to define your own annotations.
Details
Note that both a missing key or undefined is used to indicate that the
annotation is not present.
This means that can remove any annotation by setting it to undefined.
Example (Defining your own annotations)
import { Schema } from "effect"
// Extend the Annotations interface with a custom `version` annotation
declare module "effect/Schema" {
namespace Annotations {
interface Annotations {
readonly version?:
| readonly [major: number, minor: number, patch: number]
| undefined
}
}
}
// The `version` annotation is now recognized by the TypeScript compiler
const schema = Schema.String.annotate({ version: [1, 2, 0] })
// const version: readonly [major: number, minor: number, patch: number] | undefined
const version = Schema.resolveAnnotations(schema)?.["version"]
if (version) {
// Access individual parts of the version
console.log(version[1])
// Output: 2
}
Annotations | undefined
readonly String.checks: ReadonlyArray<Check<StringMeta>>checks: interface ReadonlyArray<T>ReadonlyArray<type Check<M> = Filter<M> | FilterGroup<M>A validation constraint attached to a type. Either a single
Filter
or a
FilterGroup
combining multiple checks.
Check<type StringMeta = {
readonly _tag: "isStringFinite";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isStringBigInt";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isStringSymbol";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isMinLength";
readonly minLength: number;
} | {
readonly _tag: "isMaxLength";
readonly maxLength: number;
} | {
readonly _tag: "isPattern";
readonly regExp: globalThis.RegExp;
} | {
readonly _tag: "isLengthBetween";
readonly minimum: number;
readonly maximum: number;
} | {
readonly _tag: "isTrimmed";
readonly regExp: globalThis.RegExp;
} | ... 11 more ... | {
...;
}
Metadata union for string-specific validation checks (minLength, maxLength,
pattern, UUID, trimmed, etc.).
StringMeta>>
readonly String.contentMediaType?: string | undefinedcontentMediaType?: string | undefined
readonly String.contentSchema?: Representation | undefinedcontentSchema?: type Representation =
| Declaration
| Reference
| Suspend
| Null
| Undefined
| Void
| Never
| Unknown
| Any
| String
| Number
| Boolean
| BigInt
| Symbol
| Literal
| UniqueSymbol
| ObjectKeyword
| Enum
| TemplateLiteral
| Arrays
| Objects
| Union
The core tagged union of all supported schema shapes.
Details
Each variant has a _tag discriminator. Switch on _tag to handle each
shape. Most variants carry optional annotations and some carry checks
for validation constraints.
Representation | undefined
}