Schema
Accessor
exitSchema
Signature
declare function exitSchema<SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
): Schema<Exit<SA, FA>, ExitEncoded<SI, FI, unknown>, R>;failureSchema
Signature
declare function failureSchema<SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
): Schema<FA, FI, R>;serializableSchema
Signature
declare function serializableSchema<A, I, R>(self: Serializable<A, I, R>): Schema<A, I, R>;successSchema
Signature
declare function successSchema<SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
): Schema<SA, SI, R>;Annotations
Signature
interface Annotable<Self extends Schema<A, I, R>, A, I = A, R = never> extends Schema<A, I, R> {
annotations(annotations: GenericSchema<A>): Self;
}AnnotableClass interface
Signature
interface AnnotableClass<Self extends Schema<A, I, R>, A, I = A, R = never> extends Annotable<
Self,
A,
I,
R
> {
constructor(_: never);
}annotations
Signature
declare const annotations: {
<S extends All>(annotations: GenericSchema<Type<S>>): (self: S) => ReturnType<S["annotations"]>;
<S extends All>(self: S, annotations: GenericSchema<Type<S>>): ReturnType<S["annotations"]>;
};Annotations
Api Interface
AnnotableDeclare interface
Signature
interface AnnotableDeclare<
Self extends declare<A, I, P, R>,
A,
I = A,
P extends ReadonlyArray<Schema.All> = readonly [],
R = Schema.Context<P[number]>,
> extends declare<A, I, P, R> {
constructor(_: never);
annotations(annotations: Schema<A>): Self;
}Signature
interface Array$<Value extends Schema.Any> extends TupleType<[], [Value]> {
constructor(_: never);
readonly value: Value;
annotations(annotations: Schema<readonly Array<Type<Value>>>): Array$<Value>;
}ArrayEnsure interface
Signature
interface ArrayEnsure<Value extends Schema.Any> extends transform<
Union<[Value, Array$<Value>]>,
Array$<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}Signature
interface brand<S extends Schema.Any, B extends string | symbol> extends BrandSchema<
Schema.Type<S> & Brand<B>,
Schema.Encoded<S>,
Schema.Context<S>
> {
constructor(_: never);
readonly from: S;
annotations(annotations: Schema<Type<S> & Brand<B>>): brand<S, B>;
}Signature
interface Cause<E extends Schema.All, D extends Schema.All> extends transform<
SchemaClass<
CauseEncoded<Schema.Type<E>, Schema.Type<Defect>>,
CauseEncoded<Schema.Encoded<E>, Schema.Encoded<Defect>>,
Schema.Context<E> | Schema.Context<D>
>,
CauseFromSelf<SchemaClass<Schema.Type<E>>, SchemaClass<Schema.Type<D>>>
> {
constructor(_: never);
}CauseFromSelf interface
Signature
interface CauseFromSelf<E extends Schema.All, D extends Schema.All> extends AnnotableDeclare<
CauseFromSelf<E, D>,
cause_.Cause<Schema.Type<E>>,
cause_.Cause<Schema.Encoded<E>>,
[E, D]
> {
constructor(_: never);
}Signature
interface Chunk<Value extends Schema.Any> extends transform<
Array$<Value>,
ChunkFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}ChunkFromSelf interface
Signature
interface ChunkFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
ChunkFromSelf<Value>,
chunk_.Chunk<Schema.Type<Value>>,
chunk_.Chunk<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}Signature
interface Class<Self, Fields extends Struct.Fields, I, R, C, Inherited, Proto> extends Schema<Self, Simplify<I>, R> {
constructor(props: RequiredKeys<C> extends never ? void | { [K in string | number | symbol]: C[K] } : { [K in string | number | symbol]: C[K] }, options?: MakeOptions);
readonly ast: Transformation;
readonly fields: { [K in string | number | symbol]: Fields[K] };
readonly identifier: string;
annotations(annotations: Schema<Self>): SchemaClass<Self, { [K in string | number | symbol]: I[K] }, R>;
extend<Extended = never>(identifier: string): <NewFields extends Fields>(fields: NewFields | HasFields<NewFields>, annotations?: ClassAnnotations<Extended, { [K in string | number | symbol]: Type<Fields & NewFields>[K] }>) => [Extended] extends [never] ? "Missing `Self` generic - use `class Self extends Base.extend<Self>()({ ... })`" : Class<Extended, Fields & NewFields, I & { [K in string | number | symbol]: Encoded<NewFields[K]> } & { [K in string | number | symbol]: Encoded<NewFields[K]> }, R | Context<NewFields[keyof NewFields]>, C & Constructor<NewFields>, Self, Proto>;
make<C extends (...args: Array<any>) => any>(this: C, ...args: ConstructorParameters<C>): InstanceType<C>;
transformOrFail<Transformed = never>(identifier: string): <NewFields extends Fields, R2, R3>(fields: NewFields, options: {
readonly decode: (input: { [K in string | number | symbol]: Type<Fields>[K] }, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: Type<Fields & NewFields>[K] }, ParseIssue, R2>;
readonly encode: (input: { [K in string | number | symbol]: Type<Fields & NewFields>[K] }, options: ParseOptions, ast: Transformation) => Effect<Type<Fields>, ParseIssue, R3>;
}, annotations?: ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<Fields & NewFields>[K] }>) => [Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFail<Self>()({ ... })`" : Class<Transformed, Fields & NewFields, I, R | R2 | R3 | Context<NewFields[keyof NewFields]>, C & Constructor<NewFields>, Self, Proto>;
transformOrFailFrom<Transformed = never>(identifier: string): <NewFields extends Fields, R2, R3>(fields: NewFields, options: {
readonly decode: (input: { [K in string | number | symbol]: I[K] }, options: ParseOptions, ast: Transformation) => Effect<{ [K in string | number | symbol]: I & { [K in string | number | symbol]: Encoded<NewFields[K]> } & { [K in string | number | symbol]: Encoded<...[...]> }[K] }, ParseIssue, R2>;
readonly encode: (input: { [K in string | number | symbol]: I & { [K in string | number | symbol]: Encoded<NewFields[K]> } & { [K in string | number | symbol]: Encoded<NewFields[K]> }[K] }, options: ParseOptions, ast: Transformation) => Effect<I, ParseIssue, R3>;
}, annotations?: ClassAnnotations<Transformed, { [K in string | number | symbol]: Type<Fields & NewFields>[K] }>) => [Transformed] extends [never] ? "Missing `Self` generic - use `class Self extends Base.transformOrFailFrom<Self>()({ ... })`" : Class<Transformed, Fields & NewFields, I, R | R2 | R3 | Context<NewFields[keyof NewFields]>, C & Constructor<NewFields>, Self, Proto>;
}Signature
interface Data<Value extends Schema.Any> extends transform<
Value,
DataFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}DataFromSelf interface
Signature
interface DataFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
DataFromSelf<Value>,
Schema.Type<Value>,
Schema.Encoded<Value>,
[Value]
> {
constructor(_: never);
}Signature
interface declare<
A,
I = A,
P extends ReadonlyArray<Schema.All> = readonly [],
R = Schema.Context<P[number]>,
> extends AnnotableClass<declare<A, I, P, R>, A, I, R> {
constructor(_: never);
readonly typeParameters: Readonly<P>;
}Signature
interface Either<Right extends Schema.All, Left extends Schema.All> extends transform<
Union<
[
Struct<{
_tag: Literal<["Right"]>;
right: Right;
}>,
Struct<{
_tag: Literal<["Left"]>;
left: Left;
}>,
]
>,
EitherFromSelf<SchemaClass<Schema.Type<Right>>, SchemaClass<Schema.Type<Left>>>
> {
constructor(_: never);
}EitherFromSelf interface
Signature
interface EitherFromSelf<R extends Schema.All, L extends Schema.All> extends AnnotableDeclare<
EitherFromSelf<R, L>,
either_.Either<Schema.Type<R>, Schema.Type<L>>,
either_.Either<Schema.Encoded<R>, Schema.Encoded<L>>,
[R, L]
> {
constructor(_: never);
}EitherFromUnion interface
Signature
interface EitherFromUnion<Right extends Schema.All, Left extends Schema.All> extends transform<
Union<
[
transform<
Right,
Struct<{
_tag: Literal<["Right"]>;
right: SchemaClass<Schema.Type<Right>>;
}>
>,
transform<
Left,
Struct<{
_tag: Literal<["Left"]>;
right: SchemaClass<Schema.Type<Left>>;
}>
>,
]
>,
EitherFromSelf<SchemaClass<Schema.Type<Right>>, SchemaClass<Schema.Type<Left>>>
> {
constructor(_: never);
}Signature
interface Enums<A extends EnumsDefinition> extends AnnotableClass<Enums<A>, A[keyof A]> {
constructor(_: never);
readonly enums: A;
}Signature
interface Exit<A extends Schema.All, E extends Schema.All, D extends Schema.All> extends transform<
Union<
[
Struct<{
_tag: Literal<["Failure"]>;
cause: SchemaClass<
CauseEncoded<Schema.Type<E>, Schema.Type<D>>,
CauseEncoded<Schema.Encoded<E>, Schema.Encoded<D>>,
Schema.Context<E> | Schema.Context<D>
>;
}>,
Struct<{
_tag: Literal<["Success"]>;
value: A;
}>,
]
>,
ExitFromSelf<
SchemaClass<Schema.Type<A>>,
SchemaClass<Schema.Type<E>>,
SchemaClass<Schema.Type<D>>
>
> {
constructor(_: never);
}ExitFromSelf interface
Signature
interface ExitFromSelf<
A extends Schema.All,
E extends Schema.All,
D extends Schema.All,
> extends AnnotableDeclare<
ExitFromSelf<A, E, D>,
exit_.Exit<Schema.Type<A>, Schema.Type<E>>,
exit_.Exit<Schema.Encoded<A>, Schema.Encoded<E>>,
[A, E, D]
> {
constructor(_: never);
}Signature
interface extend<Self extends Schema.Any, That extends Schema.Any> extends AnnotableClass<
extend<Self, That>,
Schema.Type<Self> & Schema.Type<That>,
Schema.Encoded<Self> & Schema.Encoded<That>,
Schema.Context<Self> | Schema.Context<That>
> {
constructor(_: never);
}Signature
interface filter<From extends Schema.Any> extends refine<Schema.Type<From>, From> {
constructor(_: never);
}filterEffect interface
Signature
interface filterEffect<S extends Schema.Any, FD = never> extends transformOrFail<
S,
SchemaClass<Schema.Type<S>>,
FD
> {
constructor(_: never);
}Signature
interface HashMap<K extends Schema.Any, V extends Schema.Any> extends transform<
Array$<Tuple2<K, V>>,
HashMapFromSelf<SchemaClass<Schema.Type<K>>, SchemaClass<Schema.Type<V>>>
> {
constructor(_: never);
}HashMapFromSelf interface
Signature
interface HashMapFromSelf<K extends Schema.Any, V extends Schema.Any> extends AnnotableDeclare<
HashMapFromSelf<K, V>,
hashMap_.HashMap<Schema.Type<K>, Schema.Type<V>>,
hashMap_.HashMap<Schema.Encoded<K>, Schema.Encoded<V>>,
[K, V]
> {
constructor(_: never);
}Signature
interface HashSet<Value extends Schema.Any> extends transform<
Array$<Value>,
HashSetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}HashSetFromSelf interface
Signature
interface HashSetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
HashSetFromSelf<Value>,
hashSet_.HashSet<Schema.Type<Value>>,
hashSet_.HashSet<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}instanceOf interface
Signature
interface instanceOf<A> extends AnnotableDeclare<instanceOf<A>, A> {
constructor(_: never);
}Signature
interface List<Value extends Schema.Any> extends transform<
Array$<Value>,
ListFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}ListFromSelf interface
Signature
interface ListFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
ListFromSelf<Value>,
list_.List<Schema.Type<Value>>,
list_.List<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}Signature
interface Literal<
Literals extends array_.NonEmptyReadonlyArray<AST.LiteralValue>,
> extends AnnotableClass<Literal<Literals>, Literals[number]> {
constructor(_: never);
readonly literals: Readonly<Literals>;
}Signature
interface Map$<K extends Schema.Any, V extends Schema.Any> extends transform<
Array$<Tuple2<K, V>>,
MapFromSelf<SchemaClass<Schema.Type<K>>, SchemaClass<Schema.Type<V>>>
> {
constructor(_: never);
}MapFromSelf interface
Signature
interface MapFromSelf<K extends Schema.Any, V extends Schema.Any> extends AnnotableDeclare<
MapFromSelf<K, V>,
Map<Schema.Type<K>, Schema.Type<V>>,
ReadonlyMap<Schema.Encoded<K>, Schema.Encoded<V>>,
[K, V]
> {
constructor(_: never);
}Signature
interface mutable<S extends Schema.Any> extends AnnotableClass<
mutable<S>,
SimplifyMutable<Schema.Type<S>>,
SimplifyMutable<Schema.Encoded<S>>,
Schema.Context<S>
> {
constructor(_: never);
}NonEmptyArray interface
Signature
interface NonEmptyArray<Value extends Schema.Any> extends AnnotableClass<
NonEmptyArray<Value>,
array_.NonEmptyReadonlyArray<Schema.Type<Value>>,
array_.NonEmptyReadonlyArray<Schema.Encoded<Value>>,
Schema.Context<Value>
> {
constructor(_: never);
readonly elements: readonly [Value];
readonly rest: readonly [Value];
readonly value: Value;
}NonEmptyArrayEnsure interface
Signature
interface NonEmptyArrayEnsure<Value extends Schema.Any> extends transform<
Union<[Value, NonEmptyArray<Value>]>,
NonEmptyArray<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}NonEmptyChunk interface
Signature
interface NonEmptyChunk<Value extends Schema.Any> extends transform<
NonEmptyArray<Value>,
NonEmptyChunkFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}NonEmptyChunkFromSelf interface
Signature
interface NonEmptyChunkFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
NonEmptyChunkFromSelf<Value>,
chunk_.NonEmptyChunk<Schema.Type<Value>>,
chunk_.NonEmptyChunk<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}Signature
interface NullishOr<S extends Schema.All> extends Union<[S, typeof Null, typeof Undefined]> {
constructor(_: never);
annotations(annotations: Schema<Type<S> | null | undefined>): NullishOr<S>;
}Signature
interface NullOr<S extends Schema.All> extends Union<[S, typeof Null]> {
constructor(_: never);
annotations(annotations: Schema<Type<S> | null>): NullOr<S>;
}Signature
interface Option<Value extends Schema.Any> extends transform<
Union<
[
Struct<{
_tag: Literal<["None"]>;
}>,
Struct<{
_tag: Literal<["Some"]>;
value: Value;
}>,
]
>,
OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}Signature
interface optional<S extends Schema.All> extends PropertySignature<
"?:",
Schema.Type<S> | undefined,
never,
"?:",
Schema.Encoded<S> | undefined,
false,
Schema.Context<S>
> {
readonly from: S;
annotations(annotations: Annotations<Type<S> | undefined>): optional<S>;
}optionalWith interface
Signature
interface optionalWith<S extends Schema.All, Options> extends PropertySignature<
Types.Has<Options, "as" | "default"> extends true ? ":" : "?:",
Types.Has<Options, "as"> extends true
? option_.Option<Schema.Type<S>>
: Schema.Type<S> | Types.Has<Options, "as" | "default" | "exact"> extends true
? never
: undefined,
never,
"?:",
Schema.Encoded<S> | Types.Has<Options, "nullable"> extends true
? null
: never | Types.Has<Options, "exact"> extends true
? never
: undefined,
Types.Has<Options, "default">,
Schema.Context<S>
> {
readonly from: S;
annotations(
annotations: Annotations<
Has<Options, "as"> extends true
? Option<Type<S>>
: Type<S> | Has<Options, "default" | "as" | "exact"> extends true
? never
: undefined
>,
): optionalWith<S, Options>;
}OptionFromNullishOr interface
Signature
interface OptionFromNullishOr<Value extends Schema.Any> extends transform<
NullishOr<Value>,
OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}OptionFromNullOr interface
Signature
interface OptionFromNullOr<Value extends Schema.Any> extends transform<
NullOr<Value>,
OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}OptionFromSelf interface
Signature
interface OptionFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
OptionFromSelf<Value>,
option_.Option<Schema.Type<Value>>,
option_.Option<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}OptionFromUndefinedOr interface
Signature
interface OptionFromUndefinedOr<Value extends Schema.Any> extends transform<
UndefinedOr<Value>,
OptionFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}ReadonlyMap$ interface
Signature
interface ReadonlyMap$<K extends Schema.Any, V extends Schema.Any> extends transform<
Array$<Tuple2<K, V>>,
ReadonlyMapFromSelf<SchemaClass<Schema.Type<K>>, SchemaClass<Schema.Type<V>>>
> {
constructor(_: never);
}ReadonlyMapFromSelf interface
Signature
interface ReadonlyMapFromSelf<K extends Schema.Any, V extends Schema.Any> extends AnnotableDeclare<
ReadonlyMapFromSelf<K, V>,
ReadonlyMap<Schema.Type<K>, Schema.Type<V>>,
ReadonlyMap<Schema.Encoded<K>, Schema.Encoded<V>>,
[K, V]
> {
constructor(_: never);
}ReadonlySet$ interface
Signature
interface ReadonlySet$<Value extends Schema.Any> extends transform<
Array$<Value>,
ReadonlySetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}ReadonlySetFromSelf interface
Signature
interface ReadonlySetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
ReadonlySetFromSelf<Value>,
ReadonlySet<Schema.Type<Value>>,
ReadonlySet<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}Signature
interface Record$<K extends Schema.All, V extends Schema.All> extends AnnotableClass<
Record$<K, V>,
{ [P in Schema.Type<K>]: Schema.Type<V> },
{ [P in Schema.Encoded<K>]: Schema.Encoded<V> },
Schema.Context<K> | Schema.Context<V>
> {
constructor(_: never);
readonly fields: {};
readonly key: K;
readonly records: readonly [
{
readonly key: K;
readonly value: V;
},
];
readonly value: V;
annotations(annotations: Schema<{ [P in any]: Type<V> }>): Record$<K, V>;
make(props: void | { [P in any]: Type<V> }, options?: MakeOptions): { [P in any]: Type<V> };
}Signature
interface Redacted<Value extends Schema.Any> extends transform<
Value,
RedactedFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}RedactedFromSelf interface
Signature
interface RedactedFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
RedactedFromSelf<Value>,
redacted_.Redacted<Schema.Type<Value>>,
redacted_.Redacted<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}Signature
interface refine<A, From extends Schema.Any> extends AnnotableClass<
refine<A, From>,
A,
Schema.Encoded<From>,
Schema.Context<From>
> {
constructor(_: never);
readonly [RefineSchemaId]: From;
readonly filter: (a: Type<From>, options: ParseOptions, self: Refinement) => Option<ParseIssue>;
readonly from: From;
make(a: Type<From>, options?: MakeOptions): A;
}Signature
interface Set$<Value extends Schema.Any> extends transform<
Array$<Value>,
SetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}SetFromSelf interface
Signature
interface SetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
SetFromSelf<Value>,
Set<Schema.Type<Value>>,
ReadonlySet<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}Signature
interface SortedSet<Value extends Schema.Any> extends transform<
Array$<Value>,
SortedSetFromSelf<SchemaClass<Schema.Type<Value>>>
> {
constructor(_: never);
}SortedSetFromSelf interface
Signature
interface SortedSetFromSelf<Value extends Schema.Any> extends AnnotableDeclare<
SortedSetFromSelf<Value>,
sortedSet_.SortedSet<Schema.Type<Value>>,
sortedSet_.SortedSet<Schema.Encoded<Value>>,
[Value]
> {
constructor(_: never);
}Signature
interface Struct<Fields extends Struct.Fields> extends AnnotableClass<Struct<Fields>, Simplify<Struct.Type<Fields>>, Simplify<Struct.Encoded<Fields>>, Struct.Context<Fields>> {
constructor(_: never);
readonly fields: Readonly<Fields>;
readonly records: readonly [];
annotations(annotations: Schema<{ [K in string | number | symbol]: Type<Fields>[K] }>): Struct<Fields>;
make(props: RequiredKeys<Constructor<Fields>> extends never ? void | { [K in string | number | symbol]: Constructor<Fields>[K] } : { [K in string | number | symbol]: Constructor<Fields>[K] }, options?: MakeOptions): { [K in string | number | symbol]: Type<Fields>[K] };
omit<Keys extends readonly Array<keyof Fields>>(...keys: Keys): Struct<{ [K in string | number | symbol]: Omit<Fields, Keys[number]>[K] }>;
pick<Keys extends readonly Array<keyof Fields>>(...keys: Keys): Struct<{ [K in string | number | symbol]: Pick<Fields, Keys[number]>[K] }>;
}Signature
interface suspend<A, I, R> extends AnnotableClass<suspend<A, I, R>, A, I, R> {
constructor(_: never);
}Signature
interface tag<Tag extends AST.LiteralValue> extends PropertySignature<
":",
Tag,
never,
":",
Tag,
true,
never
> {}TaggedClass interface
Signature
interface TaggedClass<Self, Tag extends string, Fields extends Struct.Fields> extends Class<
Self,
Fields,
Struct.Encoded<Fields>,
Struct.Context<Fields>,
Struct.Constructor<Omit<Fields, "_tag">>,
{},
{}
> {
constructor(
props: RequiredKeys<Constructor<Omit<Fields, "_tag">>> extends never
? void | { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] }
: { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] },
options?: MakeOptions,
);
readonly _tag: Tag;
}TaggedErrorClass interface
Signature
interface TaggedErrorClass<Self, Tag extends string, Fields extends Struct.Fields> extends Class<
Self,
Fields,
Struct.Encoded<Fields>,
Struct.Context<Fields>,
Struct.Constructor<Omit<Fields, "_tag">>,
{},
cause_.YieldableError
> {
constructor(
props: RequiredKeys<Constructor<Omit<Fields, "_tag">>> extends never
? void | { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] }
: { [K in string | number | symbol]: Constructor<Omit<Fields, "_tag">>[K] },
options?: MakeOptions,
);
readonly _tag: Tag;
}TaggedRequestClass interface
Signature
interface TaggedRequestClass<
Self,
Tag extends string,
Payload extends Struct.Fields,
Success extends Schema.All,
Failure extends Schema.All,
> extends Class<
Self,
Payload,
Struct.Encoded<Payload>,
Struct.Context<Payload>,
Struct.Constructor<Omit<Payload, "_tag">>,
TaggedRequest<
Tag,
Self,
Struct.Encoded<Payload>,
Struct.Context<Payload>,
Schema.Type<Success>,
Schema.Encoded<Success>,
Schema.Type<Failure>,
Schema.Encoded<Failure>,
Schema.Context<Success> | Schema.Context<Failure>
>,
{}
> {
constructor(
props: RequiredKeys<Constructor<Omit<Payload, "_tag">>> extends never
? void | { [K in string | number | symbol]: Constructor<Omit<Payload, "_tag">>[K] }
: { [K in string | number | symbol]: Constructor<Omit<Payload, "_tag">>[K] },
options?: MakeOptions,
);
readonly _tag: Tag;
readonly failure: Failure;
readonly success: Success;
}TaggedStruct type
Signature
type TaggedStruct<Tag extends AST.LiteralValue, Fields extends Struct.Fields> = Struct<
{
_tag: tag<Tag>;
} & Fields
>;Signature
interface transform<From extends Schema.All, To extends Schema.All> extends transformOrFail<
From,
To
> {
constructor(_: never);
annotations(annotations: Schema<Type<To>>): transform<From, To>;
}transformLiteral interface
Signature
interface transformLiteral<
Type extends AST.LiteralValue,
Encoded extends AST.LiteralValue,
> extends transform<Literal<[Encoded]>, Literal<[Type]>> {
constructor(_: never);
annotations(annotations: Schema<Type>): transformLiteral<Type, Encoded>;
}transformOrFail interface
Signature
interface transformOrFail<
From extends Schema.All,
To extends Schema.All,
R = never,
> extends AnnotableClass<
transformOrFail<From, To, R>,
Schema.Type<To>,
Schema.Encoded<From>,
Schema.Context<From> | Schema.Context<To> | R
> {
constructor(_: never);
readonly from: From;
readonly to: To;
}Signature
interface Tuple<Elements extends TupleType.Elements> extends TupleType<Elements, []> {
constructor(_: never);
annotations(annotations: Schema<ElementsType<Elements, readonly []>>): Tuple<Elements>;
}Signature
interface Tuple2<Fst extends Schema.Any, Snd extends Schema.Any> extends AnnotableClass<
Tuple2<Fst, Snd>,
readonly [Schema.Type<Fst>, Schema.Type<Snd>],
readonly [Schema.Encoded<Fst>, Schema.Encoded<Snd>],
Schema.Context<Fst> | Schema.Context<Snd>
> {
constructor(_: never);
readonly elements: readonly [Fst, Snd];
readonly rest: readonly [];
}Signature
interface TupleType<
Elements extends TupleType.Elements,
Rest extends TupleType.Rest,
> extends AnnotableClass<
TupleType<Elements, Rest>,
TupleType.Type<Elements, Rest>,
TupleType.Encoded<Elements, Rest>,
Schema.Context<Elements[number]> | Schema.Context<Rest[number]>
> {
constructor(_: never);
readonly elements: Readonly<Elements>;
readonly rest: Readonly<Rest>;
}TypeLiteral interface
Signature
interface TypeLiteral<
Fields extends Struct.Fields,
Records extends IndexSignature.Records,
> extends AnnotableClass<
TypeLiteral<Fields, Records>,
Simplify<TypeLiteral.Type<Fields, Records>>,
Simplify<TypeLiteral.Encoded<Fields, Records>>,
Struct.Context<Fields> | IndexSignature.Context<Records>
> {
constructor(_: never);
readonly fields: Readonly<Fields>;
readonly records: Readonly<Records>;
annotations(
annotations: Schema<{ [K in string | number | symbol]: Type<Fields, Records>[K] }>,
): TypeLiteral<Fields, Records>;
make(
props: RequiredKeys<Constructor<Fields, Records>> extends never
? void | { [K in string | number | symbol]: Constructor<Fields, Records>[K] }
: { [K in string | number | symbol]: Constructor<Fields, Records>[K] },
options?: MakeOptions,
): { [K in string | number | symbol]: Type<Fields, Records>[K] };
}UndefinedOr interface
Signature
interface UndefinedOr<S extends Schema.All> extends Union<[S, typeof Undefined]> {
constructor(_: never);
annotations(annotations: Schema<Type<S> | undefined>): UndefinedOr<S>;
}Signature
interface Union<Members extends ReadonlyArray<Schema.All>> extends AnnotableClass<
Union<Members>,
Schema.Type<Members[number]>,
Schema.Encoded<Members[number]>,
Schema.Context<Members[number]>
> {
constructor(_: never);
readonly members: Readonly<Members>;
}API Interface
Signature
interface Element<S extends Schema.Any, Token extends Element.Token> extends Variance<
Schema.Type<S>,
Schema.Encoded<S>,
Schema.Context<S>
> {
readonly _Token: Token;
readonly ast: OptionalType;
readonly from: S;
annotations(annotations: Annotations<Type<S>>): Element<S, Token>;
}propertySignature interface
Signature
interface propertySignature<S extends Schema.All> extends PropertySignature<
":",
Schema.Type<S>,
never,
":",
Schema.Encoded<S>,
false,
Schema.Context<S>
> {
readonly from: S;
annotations(annotations: Annotations<Type<S>>): propertySignature<S>;
}TemplateLiteral interface
Signature
interface TemplateLiteral<A> extends SchemaClass<A> {
constructor(_: never);
}TemplateLiteralParser interface
Signature
interface TemplateLiteralParser<
Params extends array_.NonEmptyReadonlyArray<TemplateLiteralParserParameters>,
> extends Schema<
GetTemplateLiteralParserType<Params>,
GetTemplateLiteralParserEncoded<Params>,
Schema.Context<Params[number]>
> {
readonly params: Params;
}ArrayFormatter
ArrayFormatterIssue
Signature
declare class ArrayFormatterIssue extends Variance<{
readonly _tag: "Composite" | "Pointer" | "Unexpected" | "Missing" | "Refinement" | "Transformation" | "Type" | "Forbidden";
readonly message: string;
readonly path: readonly Array<string | number | symbol>;
}, {
_tag: "Composite" | "Pointer" | "Unexpected" | "Missing" | "Refinement" | "Transformation" | "Type" | "Forbidden";
message: string;
path: readonly Array<string | number | {
_tag: "symbol";
key: string;
}>;
}, never, this> {
constructor(_: never);
}BigDecimal Constructors
BigDecimalFromSelf
Signature
declare class BigDecimalFromSelf extends Variance<BigDecimal, BigDecimal, never, this> {
constructor(_: never);
}NegativeBigDecimalFromSelf
Signature
declare const NegativeBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;NonNegativeBigDecimalFromSelf
Signature
declare const NonNegativeBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;NonPositiveBigDecimalFromSelf
Signature
declare const NonPositiveBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;PositiveBigDecimalFromSelf
Signature
declare const PositiveBigDecimalFromSelf: filter<Schema<bigDecimal_.BigDecimal>>;BigDecimal Filters
betweenBigDecimal
Signature
declare function betweenBigDecimal<S extends Any>(
minimum: BigDecimal,
maximum: BigDecimal,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanBigDecimal
Signature
declare function greaterThanBigDecimal<S extends Any>(
min: BigDecimal,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanOrEqualToBigDecimal
Signature
declare function greaterThanOrEqualToBigDecimal<S extends Any>(
min: BigDecimal,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanBigDecimal
Signature
declare function lessThanBigDecimal<S extends Any>(
max: BigDecimal,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanOrEqualToBigDecimal
Signature
declare function lessThanOrEqualToBigDecimal<S extends Any>(
max: BigDecimal,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;negativeBigDecimal
Signature
declare function negativeBigDecimal<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;nonNegativeBigDecimal
Signature
declare function nonNegativeBigDecimal<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;nonPositiveBigDecimal
Signature
declare function nonPositiveBigDecimal<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;positiveBigDecimal
Signature
declare function positiveBigDecimal<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends BigDecimal>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;BigDecimal Transformations
BigDecimal
Signature
declare class BigDecimal extends Variance<BigDecimal, string, never, this> {
constructor(_: never);
}BigDecimalFromNumber
A schema that transforms a number into a BigDecimal. When encoding, this Schema will produce incorrect results if the BigDecimal exceeds the 64-bit range of a number.
Signature
declare class BigDecimalFromNumber extends Variance<BigDecimal, number, never, this> {
constructor(_: never);
}clampBigDecimal
Clamps a BigDecimal between a minimum and a maximum value.
Signature
declare function clampBigDecimal(
minimum: BigDecimal,
maximum: BigDecimal,
): <S extends Any, A extends BigDecimal>(
self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;Bigint Constructors
NegativeBigInt
Signature
declare const NegativeBigInt: filter<Schema<bigint, string>>;NegativeBigIntFromSelf
Signature
declare const NegativeBigIntFromSelf: filter<Schema<bigint>>;NonNegativeBigInt
Signature
declare const NonNegativeBigInt: filter<Schema<bigint, string>>;NonNegativeBigIntFromSelf
Signature
declare const NonNegativeBigIntFromSelf: filter<Schema<bigint>>;NonPositiveBigInt
Signature
declare const NonPositiveBigInt: filter<Schema<bigint, string>>;NonPositiveBigIntFromSelf
Signature
declare const NonPositiveBigIntFromSelf: filter<Schema<bigint>>;PositiveBigInt
Signature
declare const PositiveBigInt: filter<Schema<bigint, string>>;PositiveBigIntFromSelf
Signature
declare const PositiveBigIntFromSelf: filter<Schema<bigint>>;Bigint Filters
betweenBigInt
Signature
declare function betweenBigInt<S extends Any>(
min: bigint,
max: bigint,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanBigInt
Signature
declare function greaterThanBigInt<S extends Any>(
min: bigint,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanOrEqualToBigInt
Signature
declare function greaterThanOrEqualToBigInt<S extends Any>(
min: bigint,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanBigInt
Signature
declare function lessThanBigInt<S extends Any>(
max: bigint,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanOrEqualToBigInt
Signature
declare function lessThanOrEqualToBigInt<S extends Any>(
max: bigint,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;negativeBigInt
Signature
declare function negativeBigInt<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;nonNegativeBigInt
Signature
declare function nonNegativeBigInt<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;nonPositiveBigInt
Signature
declare function nonPositiveBigInt<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;positiveBigInt
Signature
declare function positiveBigInt<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends bigint>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Bigint Transformations
BigIntFromNumber
This schema transforms a number into a bigint by parsing the number using the BigInt function.
It returns an error if the value can't be safely encoded as a number due to being out of range.
Signature
declare class BigIntFromNumber extends Variance<bigint, number, never, this> {
constructor(_: never);
}clampBigInt
Clamps a bigint between a minimum and a maximum value.
Signature
declare function clampBigInt(
minimum: bigint,
maximum: bigint,
): <S extends Any, A extends bigint>(
self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;Boolean Constructors
BooleanFromUnknown
Converts an arbitrary value to a boolean by testing whether it is truthy. Uses !!val to coerce the value to a boolean.
See
https://developer.mozilla.org/docs/Glossary/Truthy
Signature
declare class BooleanFromUnknown extends Variance<boolean, unknown, never, this> {
constructor(_: never);
}Boolean Transformations
BooleanFromString
Converts an string value into its corresponding boolean ("true" as true and "false" as false).
Signature
declare class BooleanFromString extends Variance<boolean, "true" | "false", never, this> {
constructor(_: never);
}Signature
declare class Not extends Variance<boolean, boolean, never, this> {
constructor(_: never);
}Branding
Returns a nominal branded schema by applying a brand to a given schema.
Signature
declare const brand: <S extends Any, B extends string | symbol>(
brand: B,
annotations?: Schema<Type<S> & Brand<B>, readonly []>,
) => (self: S) => brand<S, B>;Example
Schema<A> + B -> Schema<A & Brand<B>>Example
import * as Schema from "effect/Schema"
const Int = Schema.Number.pipe(Schema.int(), Schema.brand("Int"))
type Int = Schema.Schema.Type<typeof Int> // number & Brand<"Int">BrandSchema interface
Signature
interface BrandSchema<A extends Brand<any>, I = A, R = never> extends AnnotableClass<
BrandSchema<A, I, R>,
A,
I,
R
> {
constructor(_: never);
make(a: Unbranded<A>, options?: MakeOptions): A;
}Cause Transformations
Signature
declare const Cause: <E extends All, D extends All>(__namedParameters: {
readonly defect: D;
readonly error: E;
}) => Cause<E, D>;CauseFromSelf
Signature
declare const CauseFromSelf: <E extends All, D extends All>(__namedParameters: {
readonly defect: D;
readonly error: E;
}) => CauseFromSelf<E, D>;Cause Utils
CauseEncoded type
Signature
type CauseEncoded<E, D> =
| {
readonly _tag: "Empty";
}
| {
readonly _tag: "Fail";
readonly error: E;
}
| {
readonly _tag: "Die";
readonly defect: D;
}
| {
readonly _tag: "Interrupt";
readonly fiberId: FiberIdEncoded;
}
| {
readonly _tag: "Sequential";
readonly left: CauseEncoded<E, D>;
readonly right: CauseEncoded<E, D>;
}
| {
readonly _tag: "Parallel";
readonly left: CauseEncoded<E, D>;
readonly right: CauseEncoded<E, D>;
};Chunk
ChunkFromSelf
Signature
declare const ChunkFromSelf: <Value extends Any>(value: Value) => ChunkFromSelf<Value>;NonEmptyChunkFromSelf
Signature
declare const NonEmptyChunkFromSelf: <Value extends Any>(
value: Value,
) => NonEmptyChunkFromSelf<Value>;Chunk Transformations
Signature
declare function Chunk<Value extends Any>(value: Value): Chunk<Value>;NonEmptyChunk
Signature
declare function NonEmptyChunk<Value extends Any>(value: Value): NonEmptyChunk<Value>;Classes
Signature
declare const Class: <Self = never>(
identifier: string,
) => <Fields extends Fields>(
fieldsOr: Fields | HasFields<Fields>,
annotations?: ClassAnnotations<Self, { [K in string | number | symbol]: Type<Fields>[K] }>,
) => [Self] extends [never]
? "Missing `Self` generic - use `class Self extends Class<Self>()({ ... })`"
: Class<
Self,
Fields,
Encoded<Fields>,
Context<Fields[keyof Fields]>,
Constructor<Fields>,
{},
{}
>;Example
import { Schema } from "effect"
class MyClass extends Schema.Class<MyClass>("MyClass")({
someField: Schema.String,
}) {
someMethod() {
return this.someField + "bar"
}
}TaggedClass
Signature
declare const TaggedClass: <Self = never>(
identifier?: string,
) => <Tag extends string, Fields extends Fields>(
tag: Tag,
fieldsOr: Fields | HasFields<Fields>,
annotations?: ClassAnnotations<
Self,
{
[K in string | number | symbol]: Type<
{
readonly _tag: tag<Tag>;
} & Fields
>[K];
}
>,
) => [Self] extends [never]
? 'Missing `Self` generic - use `class Self extends TaggedClass<Self>()("Tag", { ... })`'
: TaggedClass<
Self,
Tag,
{
readonly _tag: tag<Tag>;
} & Fields
>;Example
import { Schema } from "effect"
class MyClass extends Schema.TaggedClass<MyClass>("MyClass")("MyClass", {
a: Schema.String,
}) {}TaggedError
Signature
declare function TaggedError<Self = never>(
identifier?: string,
): <Tag extends string, Fields extends Fields>(
tag: Tag,
fieldsOr: Fields | HasFields<Fields>,
annotations?: ClassAnnotations<
Self,
{
[K in string | number | symbol]: Type<
{
readonly _tag: tag<Tag>;
} & Fields
>[K];
}
>,
) => [Self] extends [never]
? 'Missing `Self` generic - use `class Self extends TaggedError<Self>()("Tag", { ... })`'
: TaggedErrorClass<
Self,
Tag,
{
readonly _tag: tag<Tag>;
} & Fields
>;TaggedRequest
Signature
declare const TaggedRequest: <Self = never>(
identifier?: string,
) => <Tag extends string, Payload extends Fields, Success extends All, Failure extends All>(
tag: Tag,
options: {
failure: Failure;
payload: Payload;
success: Success;
},
annotations?: ClassAnnotations<
Self,
{
[K in string | number | symbol]: Type<
{
readonly _tag: tag<Tag>;
} & Payload
>[K];
}
>,
) => [Self] extends [never]
? 'Missing `Self` generic - use `class Self extends TaggedRequest<Self>()("Tag", SuccessSchema, FailureSchema, { ... })`'
: TaggedRequestClass<
Self,
Tag,
{
readonly _tag: tag<Tag>;
} & Payload,
Success,
Failure
>;Example
import { Schema } from "effect"
class MyRequest extends Schema.TaggedRequest<MyRequest>("MyRequest")("MyRequest", {
failure: Schema.String,
success: Schema.Number,
payload: { id: Schema.String },
}) {}Combinators
attachPropertySignature
Attaches a property signature with the specified key and value to the schema. This API is useful when you want to add a property to your schema which doesn't describe the shape of the input, but rather maps to another schema, for example when you want to add a discriminant to a simple union.
Signature
declare const attachPropertySignature: {
<K extends PropertyKey, V extends symbol | LiteralValue, A>(
key: K,
value: V,
annotations?: Schema<A & { [k in PropertyKey]: V }, readonly []>,
): <I, R>(schema: Schema<A, I, R>) => SchemaClass<A & { [k in PropertyKey]: V }, I, R>;
<A, I, R, K extends PropertyKey, V extends symbol | LiteralValue>(
schema: Schema<A, I, R>,
key: K,
value: V,
annotations?: Schema<A & { [k in PropertyKey]: V }, readonly []>,
): SchemaClass<A & { [k in PropertyKey]: V }, I, R>;
};Example
import * as assert from "node:assert"
import * as S from "effect/Schema"
import { pipe } from "effect/Function"
const Circle = S.Struct({ radius: S.Number })
const Square = S.Struct({ sideLength: S.Number })
const Shape = S.Union(
Circle.pipe(S.attachPropertySignature("kind", "circle")),
Square.pipe(S.attachPropertySignature("kind", "square")),
)
assert.deepStrictEqual(S.decodeSync(Shape)({ radius: 10 }), {
kind: "circle",
radius: 10,
})Signature
declare const compose: {
<To extends Any, From extends Any, C extends any>(
to: To & Schema<Type<To>, C, Context<To>>,
): (from: From) => transform<From, To>;
<To extends Any>(
to: To,
): <From extends Any, B extends any>(
from: From & Schema<B, Encoded<From>, Context<From>>,
) => transform<From, To>;
<To extends Any>(
to: To,
options?: {
readonly strict: true;
},
): <From extends Any>(
from: From & Schema<Encoded<To>, Encoded<From>, Context<From>>,
) => transform<From, To>;
<To extends Any>(
to: To,
options: {
readonly strict: false;
},
): <From extends Any>(from: From) => transform<From, To>;
<From extends Any, To extends Any, C extends any>(
from: From,
to: To & Schema<Type<To>, C, Context<To>>,
): transform<From, To>;
<From extends Any, B extends any, To extends Any>(
from: From & Schema<B, Encoded<From>, Context<From>>,
to: To,
): transform<From, To>;
<From extends Any, To extends Any>(
from: From & Schema<Encoded<To>, Encoded<From>, Context<From>>,
to: To,
options?: {
readonly strict: true;
},
): transform<From, To>;
<From extends Any, To extends Any>(
from: From,
to: To,
options: {
readonly strict: false;
},
): transform<From, To>;
};Extends a schema with another schema.
Not all extensions are supported, and their support depends on the nature of the involved schemas.
Possible extensions include: - Schema.String with another Schema.String refinement or a string literal - Schema.Number with another Schema.Number refinement or a number literal - Schema.Boolean with another Schema.Boolean refinement or a boolean literal - A struct with another struct where overlapping fields support extension - A struct with in index signature - A struct with a union of supported schemas - A refinement of a struct with a supported schema - A suspend of a struct with a supported schema - A transformation between structs where the โfromโ and โtoโ sides have no overlapping fields with the target struct
Signature
declare const extend: {
<That extends Any>(that: That): <Self extends Any>(self: Self) => extend<Self, That>;
<Self extends Any, That extends Any>(self: Self, that: That): extend<Self, That>;
};Example
import * as Schema from "effect/Schema"
const schema = Schema.Struct({
a: Schema.String,
b: Schema.String,
})
// const extended: Schema<
// {
// readonly a: string
// readonly b: string
// } & {
// readonly c: string
// } & {
// readonly [x: string]: string
// }
// >
const extended = Schema.asSchema(
schema.pipe(
Schema.extend(Schema.Struct({ c: Schema.String })), // <= you can add more fields
Schema.extend(Schema.Record({ key: Schema.String, value: Schema.String })), // <= you can add index signatures
),
)Signature
declare function keyof<A, I, R>(self: Schema<A, I, R>): SchemaClass<keyof A>;Creates a new schema with shallow mutability applied to its properties.
Signature
declare const mutable: <S extends Any>(schema: S) => mutable<S>;Signature
declare const NullishOr: <S extends All>(self: S) => NullishOr<S>;Signature
declare const NullOr: <S extends All>(self: S) => NullOr<S>;Signature
declare function partial<A, I, R>(
self: Schema<A, I, R>,
): SchemaClass<
{ [K in string | number | symbol]: A[K] },
{ [K in string | number | symbol]: I[K] },
R
>;partialWith
Signature
declare const partialWith: {
<
Options extends {
readonly exact: true;
},
>(
options: Options,
): <A, I, R>(
self: Schema<A, I, R>,
) => SchemaClass<
{ [K in string | number | symbol]: A[K] },
{ [K in string | number | symbol]: I[K] },
R
>;
<
A,
I,
R,
Options extends
| {
readonly exact: true;
}
| undefined,
>(
self: Schema<A, I, R>,
options: Options,
): SchemaClass<
{ [K in string | number | symbol]: A[K] },
{ [K in string | number | symbol]: I[K] },
R
>;
};Signature
declare function required<A, I, R>(
self: Schema<A, I, R>,
): SchemaClass<
{ [K in string | number | symbol]: A[K] },
{ [K in string | number | symbol]: I[K] },
R
>;UndefinedOr
Signature
declare const UndefinedOr: <S extends All>(self: S) => UndefinedOr<S>;Signature
declare function Union<Members extends readonly [All, All, All]>(...members: Members): Union<Members>
declare function Union<Member extends All>(member: Member): Member
declare function Union(): typeof Never
declare function Union<Members extends readonly Array<All>>(...members: Members): Schema<Type<Members[number]>, Encoded<Members[number]>, Context<Members[number]>>Config Validations
Constructor Utils
MakeOptions type
Signature
type MakeOptions =
| boolean
| {
readonly disableValidation?: boolean;
};Constructors
ArrayEnsure
Signature
declare function ArrayEnsure<Value extends Any>(value: Value): ArrayEnsure<Value>;The constraint R extends Schema.Context<P[number]> enforces dependencies solely from typeParameters. This ensures that when you call Schema.to or Schema.from, you receive a schema with a never context.
Signature
declare const declare: {
<A>(is: (input: unknown) => input is A, annotations?: Schema<A, readonly []>): declare<A>;
<A, I, P extends readonly Array<All>>(typeParameters: P, options: {
readonly decode: (...typeParameters: { [K in string | number | symbol]: Schema<Type<P[K]>, Encoded<P[K]>, never> }) => (input: unknown, options: ParseOptions, ast: Declaration) => Effect<A, ParseIssue, never>;
readonly encode: (...typeParameters: { [K in string | number | symbol]: Schema<Type<P[K]>, Encoded<P[K]>, never> }) => (input: unknown, options: ParseOptions, ast: Declaration) => Effect<I, ParseIssue, never>;
}, annotations?: Schema<A, { [K in string | number | symbol]: Type<P[K]> }>): declare<A, I, P>;
}Signature
declare const Enums: <A extends EnumsDefinition>(enums: A) => Enums<A>;Signature
declare function fromBrand<C extends Brand<string | symbol>, A extends Brand<string | symbol>>(
constructor: Constructor<C>,
annotations?: Filter<C, A>,
): <I, R>(self: Schema<A, I, R>) => BrandSchema<A & C, I, R>;instanceOf
Signature
declare const instanceOf: <A extends (...args: any) => any>(
constructor: A,
annotations?: Schema<InstanceType<A>, readonly []>,
) => instanceOf<InstanceType<A>>;Signature
declare function Literal<Literals extends readonly [LiteralValue, LiteralValue]>(...literals: Literals): Literal<Literals>
declare function Literal(): Never
declare function Literal<Literals extends readonly Array<LiteralValue>>(...literals: Literals): SchemaClass<Literals[number]>Signature
declare function make<A, I = A, R = never>(ast: AST): SchemaClass<A, I, R>;NonEmptyArray
Signature
declare const NonEmptyArray: <Value extends Any>(value: Value) => NonEmptyArray<Value>;NonEmptyArrayEnsure
Signature
declare function NonEmptyArrayEnsure<Value extends Any>(value: Value): NonEmptyArrayEnsure<Value>;pickLiteral
Creates a new Schema from a literal schema.
Signature
declare function pickLiteral<A extends LiteralValue, L extends readonly [A, A]>(
...literals: L
): <I, R>(_schema: Schema<A, I, R>) => Literal<[...Array<L>]>;Signature
declare function Record<K extends All, V extends All>(options: {
readonly key: K;
readonly value: V;
}): Record$<K, V>;Signature
declare function Struct<Fields extends Fields, Records extends readonly [Record, Record]>(
fields: Fields,
...records: Records
): TypeLiteral<Fields, Records>;
declare function Struct<Fields extends Fields>(fields: Fields): Struct<Fields>;Signature
declare const suspend: <A, I, R>(f: () => Schema<A, I, R>) => suspend<A, I, R>;TaggedStruct
A tagged struct is a struct that has a tag property that is used to distinguish between different types of objects.
The tag is optional when using the make method.
Signature
declare const TaggedStruct: <Tag extends LiteralValue, Fields extends Fields>(
value: Tag,
fields: Fields,
) => TaggedStruct<Tag, Fields>;Example
import * as assert from "node:assert"
import { Schema } from "effect"
const User = Schema.TaggedStruct("User", {
name: Schema.String,
age: Schema.Number,
})
assert.deepStrictEqual(User.make({ name: "John", age: 44 }), {
_tag: "User",
name: "John",
age: 44,
})transformLiteral
Creates a new Schema which transforms literal values.
Signature
declare function transformLiteral<Encoded extends LiteralValue, Type extends LiteralValue>(
from: Encoded,
to: Type,
): transformLiteral<Type, Encoded>;transformLiterals
Creates a new Schema which maps between corresponding literal values.
Signature
declare function transformLiterals<A extends readonly [readonly [LiteralValue, LiteralValue], readonly [LiteralValue, LiteralValue], readonly [LiteralValue, LiteralValue]]>(...pairs: A): Union<{ [I in string | number | symbol]: transformLiteral<A[I][1], A[I][0]> }>
declare function transformLiterals<Encoded extends LiteralValue, Type extends LiteralValue>(pairs: [Encoded, Type]): transformLiteral<Type, Encoded>
declare function transformLiterals<A extends readonly Array<readonly [LiteralValue, LiteralValue]>>(...pairs: A): Schema<A[number][1], A[number][0]>Signature
declare function Tuple<
Elements extends Elements,
Rest extends readonly [Any | Element<Any, "">, Any | Element<Any, "">],
>(elements: Elements, ...rest: Rest): TupleType<Elements, Rest>;
declare function Tuple<Fst extends Any, Snd extends Any>(fst: Fst, snd: Snd): Tuple2<Fst, Snd>;
declare function Tuple<Elements extends Elements>(...elements: Elements): Tuple<Elements>;UniqueSymbolFromSelf
Signature
declare function UniqueSymbolFromSelf<S extends symbol>(symbol: S): SchemaClass<S>;Data Transformations
Type and Encoded must extend Readonly<Record<string, any>> | ReadonlyArray<any> to be compatible with this API.
Signature
declare const Data: <S extends Any, A extends readonly Array<unknown> | Readonly<Record<string, unknown>>, I extends readonly Array<unknown> | Readonly<Record<string, unknown>>>(value: S & Schema<A & Type<S>, I & Encoded<S>, Context<S>>) => Data<S>DataFromSelf
Type and Encoded must extend Readonly<Record<string, any>> | ReadonlyArray<any> to be compatible with this API.
Signature
declare const DataFromSelf: <S extends Any, A extends readonly Array<unknown> | Readonly<Record<string, unknown>>, I extends readonly Array<unknown> | Readonly<Record<string, unknown>>>(value: S & Schema<A & Type<S>, I & Encoded<S>, Context<S>>) => DataFromSelf<S>Date Constructors
DateFromSelf
Describes a schema that accommodates potentially invalid Date instances, such as new Date("Invalid Date"), without rejection.
Signature
declare class DateFromSelf extends Variance<Date, Date, never, this> {
constructor(_: never);
}ValidDateFromSelf
Defines a schema that ensures only valid dates are accepted. This schema rejects values like new Date("Invalid Date"), which, despite being a Date instance, represents an invalid date. Such stringent validation ensures that all date objects processed through this schema are properly formed and represent real dates.
Signature
declare class ValidDateFromSelf extends Variance<Date, Date, never, this> {
constructor(_: never);
}Date Filters
betweenDate
Signature
declare function betweenDate<S extends Any>(
min: Date,
max: Date,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanDate
Signature
declare function greaterThanDate<S extends Any>(
min: Date,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanOrEqualToDate
Signature
declare function greaterThanOrEqualToDate<S extends Any>(
min: Date,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanDate
Signature
declare function lessThanDate<S extends Any>(
max: Date,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanOrEqualToDate
Signature
declare function lessThanOrEqualToDate<S extends Any>(
max: Date,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Defines a filter that specifically rejects invalid dates, such as new Date("Invalid Date"). This filter ensures that only properly formatted and valid date objects are accepted, enhancing data integrity by preventing erroneous date values from being processed.
Signature
declare function validDate<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Date>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Date Transformations
DateFromNumber
Defines a schema that converts a number into a Date object using the new Date constructor. This schema does not validate the numerical input, allowing potentially invalid values such as NaN, Infinity, and -Infinity to be converted into Date objects. During the encoding process, any invalid Date object will be encoded to NaN.
Signature
declare class DateFromNumber extends Variance<Date, number, never, this> {
constructor(_: never);
}DateFromString
Defines a schema that attempts to convert a string to a Date object using the new Date constructor. This conversion is lenient, meaning it does not reject strings that do not form valid dates (e.g., using new Date("Invalid Date") results in a Date object, despite being invalid).
Signature
declare class DateFromString extends Variance<Date, string, never, this> {
constructor(_: never);
}DateTime.Utc Constructors
DateTimeUtcFromSelf
Describes a schema that represents a DateTime.Utc instance.
Signature
declare class DateTimeUtcFromSelf extends Variance<Utc, Utc, never, this> {
constructor(_: never);
}DateTime.Utc Transformations
DateTimeUtc
Defines a schema that attempts to convert a string to a DateTime.Utc instance using the DateTime.unsafeMake constructor.
Signature
declare class DateTimeUtc extends Variance<Utc, string, never, this> {
constructor(_: never);
}DateTimeUtcFromDate
Defines a schema that attempts to convert a Date to a DateTime.Utc instance using the DateTime.unsafeMake constructor.
Signature
declare class DateTimeUtcFromDate extends Variance<Utc, Date, never, this> {
constructor(_: never);
}DateTimeUtcFromNumber
Defines a schema that attempts to convert a number to a DateTime.Utc instance using the DateTime.unsafeMake constructor.
Signature
declare class DateTimeUtcFromNumber extends Variance<Utc, number, never, this> {
constructor(_: never);
}DateTime.Zoned Constructors
DateTimeZonedFromSelf
Describes a schema that represents a DateTime.Zoned instance.
Signature
declare class DateTimeZonedFromSelf extends Variance<Zoned, Zoned, never, this> {
constructor(_: never);
}DateTime.Zoned Transformations
DateTimeZoned
Defines a schema that attempts to convert a string to a DateTime.Zoned instance.
Signature
declare class DateTimeZoned extends Variance<Zoned, string, never, this> {
constructor(_: never);
}Decoding
Signature
declare const decode: <A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
) => (i: I, overrideOptions?: ParseOptions) => Effect.Effect<A, ParseResult.ParseError, R>;decodeEither
Signature
declare const decodeEither: <A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
) => (i: I, overrideOptions?: ParseOptions) => either_.Either<A, ParseResult.ParseError>;decodeOption
Signature
declare const decodeOption: <A, I>(
schema: Schema.Schema<A, I, never>,
options?: AST.ParseOptions,
) => (i: I, overrideOptions?: AST.ParseOptions) => Option.Option<A>;decodePromise
Signature
declare const decodePromise: <A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
) => (i: I, overrideOptions?: ParseOptions) => Promise<A>;decodeSync
Signature
declare const decodeSync: <A, I>(
schema: Schema.Schema<A, I, never>,
options?: AST.ParseOptions,
) => (i: I, overrideOptions?: AST.ParseOptions) => A;decodeUnknown
Signature
declare function decodeUnknown<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Effect<A, ParseError, R>;decodeUnknownEither
Signature
declare function decodeUnknownEither<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Either<A, ParseError>;decodeUnknownOption
Signature
declare function decodeUnknownOption<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Option<A>;decodeUnknownPromise
Signature
declare function decodeUnknownPromise<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Promise<A>;decodeUnknownSync
Signature
declare function decodeUnknownSync<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => A;deserialize
Signature
declare const deserialize: {
(value: unknown): <A, I, R>(self: Serializable<A, I, R>) => Effect<A, ParseError, R>;
<A, I, R>(self: Serializable<A, I, R>, value: unknown): Effect<A, ParseError, R>;
};deserializeExit
Signature
declare const deserializeExit: {
(
value: unknown,
): <SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
) => Effect<Exit<SA, FA>, ParseError, R>;
<SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
value: unknown,
): Effect<Exit<SA, FA>, ParseError, R>;
};deserializeFailure
Signature
declare const deserializeFailure: {
(
value: unknown,
): <SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<FA, ParseError, R>;
<SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
value: unknown,
): Effect<FA, ParseError, R>;
};deserializeSuccess
Signature
declare const deserializeSuccess: {
(
value: unknown,
): <SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<SA, ParseError, R>;
<SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
value: unknown,
): Effect<SA, ParseError, R>;
};Defect
Defines a schema for handling JavaScript errors (Error instances) and other types of defects. It decodes objects into Error instances if they match the expected structure (i.e., have a message and optionally a name and stack), or converts other values to their string representations.
When encoding, it converts Error instances back into plain objects containing only the error's name and message, or other values into their string forms.
This is useful for serializing and deserializing errors across network boundaries where error objects do not natively serialize.
Signature
declare class Defect extends Variance<unknown, unknown, never, this> {
constructor(_: never);
}Duration Constructors
DurationFromSelf
Signature
declare class DurationFromSelf extends Variance<Duration, Duration, never, this> {
constructor(_: never);
}Duration Filters
betweenDuration
Signature
declare function betweenDuration<S extends Any>(
minimum: DurationInput,
maximum: DurationInput,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanDuration
Signature
declare function greaterThanDuration<S extends Any>(
min: DurationInput,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanOrEqualToDuration
Signature
declare function greaterThanOrEqualToDuration<S extends Any>(
min: DurationInput,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanDuration
Signature
declare function lessThanDuration<S extends Any>(
max: DurationInput,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanOrEqualToDuration
Signature
declare function lessThanOrEqualToDuration<S extends Any>(
max: DurationInput,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends Duration>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Duration Transformations
clampDuration
Clamps a Duration between a minimum and a maximum value.
Signature
declare function clampDuration(
minimum: DurationInput,
maximum: DurationInput,
): <S extends Any, A extends Duration>(
self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;A schema that converts a JSON-compatible tagged union into a Duration.
Signature
declare class Duration extends Variance<
Duration,
DurationEncoded | readonly [number, number],
never,
this
> {
constructor(_: never);
}DurationFromMillis
A schema that transforms a (possibly Infinite) non negative number into a Duration. Treats the value as the number of milliseconds.
Signature
declare class DurationFromMillis extends Variance<Duration, number, never, this> {
constructor(_: never);
}DurationFromNanos
A schema that transforms a non negative bigint into a Duration. Treats the value as the number of nanoseconds.
Signature
declare class DurationFromNanos extends Variance<Duration, bigint, never, this> {
constructor(_: never);
}Duration Utils
DurationEncoded type
Signature
type DurationEncoded =
| {
readonly _tag: "Millis";
readonly millis: number;
}
| {
readonly _tag: "Nanos";
readonly nanos: string;
}
| {
readonly _tag: "Infinity";
};Either Transformations
Signature
declare const Either: <R extends All, L extends All>(__namedParameters: {
readonly left: L;
readonly right: R;
}) => Either<R, L>;EitherFromSelf
Signature
declare const EitherFromSelf: <R extends All, L extends All>(__namedParameters: {
readonly left: L;
readonly right: R;
}) => EitherFromSelf<R, L>;EitherFromUnion
Signature
declare const EitherFromUnion: <Right extends All, Left extends All>(__namedParameters: {
readonly left: Left;
readonly right: Right;
}) => EitherFromUnion<Right, Left>;Example
import * as Schema from "effect/Schema"
// Schema<string | number, Either<string, number>>
Schema.EitherFromUnion({ left: Schema.String, right: Schema.Number })Either Utils
EitherEncoded type
Signature
type EitherEncoded<IR, IL> = RightEncoded<IR> | LeftEncoded<IL>;LeftEncoded type
Signature
type LeftEncoded<IE> = {
readonly _tag: "Left";
readonly left: IE;
};RightEncoded type
Signature
type RightEncoded<IA> = {
readonly _tag: "Right";
readonly right: IA;
};Encoding
Signature
declare const encode: <A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
) => (a: A, overrideOptions?: ParseOptions) => Effect.Effect<I, ParseResult.ParseError, R>;encodeEither
Signature
declare const encodeEither: <A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
) => (a: A, overrideOptions?: ParseOptions) => either_.Either<I, ParseResult.ParseError>;encodeOption
Signature
declare const encodeOption: <A, I>(
schema: Schema.Schema<A, I, never>,
options?: AST.ParseOptions,
) => (input: A, overrideOptions?: AST.ParseOptions) => Option.Option<I>;encodePromise
Signature
declare const encodePromise: <A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
) => (a: A, overrideOptions?: ParseOptions) => Promise<I>;encodeSync
Signature
declare const encodeSync: <A, I>(
schema: Schema.Schema<A, I, never>,
options?: AST.ParseOptions,
) => (a: A, overrideOptions?: AST.ParseOptions) => I;encodeUnknown
Signature
declare function encodeUnknown<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Effect<I, ParseError, R>;encodeUnknownEither
Signature
declare function encodeUnknownEither<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Either<I, ParseError>;encodeUnknownOption
Signature
declare function encodeUnknownOption<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Option<I>;encodeUnknownPromise
Signature
declare function encodeUnknownPromise<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Promise<I>;encodeUnknownSync
Signature
declare function encodeUnknownSync<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => I;Signature
declare function serialize<A, I, R>(self: Serializable<A, I, R>): Effect<I, ParseError, R>;serializeExit
Signature
declare const serializeExit: {
<SA, FA>(
value: Exit<SA, FA>,
): <SI, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
) => Effect<ExitEncoded<SI, FI, unknown>, ParseError, R>;
<SA, SI, FA, FI, R>(
self: WithResult<SA, SI, FA, FI, R>,
value: Exit<SA, FA>,
): Effect<ExitEncoded<SI, FI, unknown>, ParseError, R>;
};serializeFailure
Signature
declare const serializeFailure: {
<FA>(
value: FA,
): <SA, SI, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<FI, ParseError, R>;
<SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>, value: FA): Effect<FI, ParseError, R>;
};serializeSuccess
Signature
declare const serializeSuccess: {
<SA>(
value: SA,
): <SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>) => Effect<SI, ParseError, R>;
<SA, SI, FA, FI, R>(self: WithResult<SA, SI, FA, FI, R>, value: SA): Effect<SI, ParseError, R>;
};Equivalence
equivalence
Given a schema Schema<A, I, R>, returns an Equivalence instance for A.
Signature
declare function equivalence<A, I, R>(schema: Schema<A, I, R>): Equivalence<A>;Exit Transformations
Signature
declare const Exit: <A extends All, E extends All, D extends All>(__namedParameters: {
readonly defect: D;
readonly failure: E;
readonly success: A;
}) => Exit<A, E, D>;ExitFromSelf
Signature
declare const ExitFromSelf: <A extends All, E extends All, D extends All>(__namedParameters: {
readonly defect: D;
readonly failure: E;
readonly success: A;
}) => ExitFromSelf<A, E, D>;Exit Utils
ExitEncoded type
Signature
type ExitEncoded<A, E, D> =
| {
readonly _tag: "Failure";
readonly cause: CauseEncoded<E, D>;
}
| {
readonly _tag: "Success";
readonly value: A;
};FiberId
FiberIdEncoded type
Signature
type FiberIdEncoded =
| {
readonly _tag: "Composite";
readonly left: FiberIdEncoded;
readonly right: FiberIdEncoded;
}
| {
readonly _tag: "None";
}
| {
readonly _tag: "Runtime";
readonly id: number;
readonly startTimeMillis: number;
};FiberId Constructors
FiberIdFromSelf
Signature
declare class FiberIdFromSelf extends Variance<FiberId, FiberId, never, this> {
constructor(_: never);
}FiberId Transformations
Filtering
Signature
declare function filter<C, B, A = C>(
refinement: (a: A, options: ParseOptions, self: Refinement) => a is B,
annotations?: Filter<C & B, C>,
): <I, R>(self: Schema<C, I, R>) => refine<C & B, Schema<A, I, R>>;
declare function filter<A, B>(
refinement: (a: A, options: ParseOptions, self: Refinement) => a is B,
annotations?: Filter<B, A>,
): <I, R>(self: Schema<A, I, R>) => refine<B, Schema<A, I, R>>;
declare function filter<S extends Any>(
predicate: (a: NoInfer<Type<S>>, options: ParseOptions, self: Refinement) => FilterReturnType,
annotations?: Filter<NoInfer<Type<S>>, NoInfer<Type<S>>>,
): (self: S) => filter<S>;FilterIssue interface
Signature
interface FilterIssue {
readonly message: string;
readonly path: readonly Array<PropertyKey>;
}FilterOutput type
Signature
type FilterOutput = undefined | boolean | string | ParseResult.ParseIssue | FilterIssue;Formatting
Guards
isPropertySignature
Signature
declare function isPropertySignature(u: unknown): u is All<PropertyKey>;Tests if a value is a Schema.
Signature
declare function isSchema(u: unknown): u is Any;HashMap Transformations
Signature
declare const HashMap: <K extends Any, V extends Any>(__namedParameters: {
readonly key: K;
readonly value: V;
}) => HashMap<K, V>;HashMapFromSelf
Signature
declare const HashMapFromSelf: <K extends Any, V extends Any>(__namedParameters: {
readonly key: K;
readonly value: V;
}) => HashMapFromSelf<K, V>;HashSet Transformations
Signature
declare function HashSet<Value extends Any>(value: Value): HashSet<Value>;HashSetFromSelf
Signature
declare const HashSetFromSelf: <Value extends Any>(value: Value) => HashSetFromSelf<Value>;List Transformations
Signature
declare function List<Value extends Any>(value: Value): List<Value>;ListFromSelf
Signature
declare const ListFromSelf: <Value extends Any>(value: Value) => ListFromSelf<Value>;Map
MapFromSelf
Signature
declare const MapFromSelf: <K extends Any, V extends Any>(__namedParameters: {
readonly key: K;
readonly value: V;
}) => MapFromSelf<K, V>;Map Transformations
MapFromRecord
Signature
declare function MapFromRecord<KA, KR, VA, VI, VR>(__namedParameters: {
key: Schema<KA, string, KR>;
value: Schema<VA, VI, VR>;
}): SchemaClass<
Map<KA, VA>,
{
[x: string]: VI;
},
KR | VR
>;Model
Signature
interface Schema<in out A, in out I = A, out R = never> extends Variance<A, I, R>, Pipeable {
readonly ast: AST;
readonly Context: R;
readonly Encoded: I;
readonly Type: A;
annotations(annotations: GenericSchema<A>): Schema<A, I, R>;
}SchemaClass interface
Signature
interface SchemaClass<A, I = A, R = never> extends AnnotableClass<SchemaClass<A, I, R>, A, I, R> {
constructor(_: never);
}Serializable
Serializable interface
The Serializable trait allows objects to define their own schema for serialization.
Signature
interface Serializable<A, I, R> {
readonly [symbolSerializable]: Schema<A, I, R>;
}SerializableWithResult
SerializableWithResult interface
The SerializableWithResult trait is specifically designed to model remote procedures that require serialization of their input and output, managing both successful and failed outcomes.
This trait combines functionality from both the Serializable and WithResult traits to handle data serialization and the bifurcation of operation results into success or failure categories.
Signature
interface SerializableWithResult<A, I, R, Success, SuccessEncoded, Failure, FailureEncoded, ResultR>
extends
Serializable<A, I, R>,
WithResult<Success, SuccessEncoded, Failure, FailureEncoded, ResultR> {}WithResult
WithResult interface
The WithResult trait is designed to encapsulate the outcome of an operation, distinguishing between success and failure cases. Each case is associated with a schema that defines the structure and types of the success or failure data.
Signature
interface WithResult<Success, SuccessEncoded, Failure, FailureEncoded, ResultR> {
readonly [symbolWithResult]: {
readonly failure: Schema<Failure, FailureEncoded, ResultR>;
readonly success: Schema<Success, SuccessEncoded, ResultR>;
};
}NonEmptyReadonlyArray Transformations
headNonEmpty
Get the first element of a NonEmptyReadonlyArray.
Signature
declare function headNonEmpty<S extends Any, A extends readonly [unknown, unknown]>(
self: S & Schema<A, Encoded<S>, Context<S>>,
): transform<S, SchemaClass<A[number], A[number], never>>;Number Constructors
Signature
declare class Finite extends Variance<number, number, never, this> {
constructor(_: never);
}Signature
declare class Int extends Variance<number, number, never, this> {
constructor(_: never);
}JsonNumber
The JsonNumber is a schema for representing JSON numbers. It ensures that the provided value is a valid number by filtering out NaN and (+/-) Infinity. This is useful when you want to validate and represent numbers in JSON format.
Signature
declare class JsonNumber extends Variance<number, number, never, this> {
constructor(_: never);
}Example
import * as assert from "node:assert"
import * as Schema from "effect/Schema"
const is = Schema.is(Schema.JsonNumber)
assert.deepStrictEqual(is(42), true)
assert.deepStrictEqual(is(Number.NaN), false)
assert.deepStrictEqual(is(Number.POSITIVE_INFINITY), false)
assert.deepStrictEqual(is(Number.NEGATIVE_INFINITY), false)Signature
declare class Negative extends Variance<number, number, never, this> {
constructor(_: never);
}Signature
declare class NonNaN extends Variance<number, number, never, this> {
constructor(_: never);
}NonNegative
Signature
declare class NonNegative extends Variance<number, number, never, this> {
constructor(_: never);
}NonNegativeInt
A non-negative integer. +Infinity is excluded.
Signature
declare const NonNegativeInt: refine<number, typeof NonNegative>;NonPositive
Signature
declare class NonPositive extends Variance<number, number, never, this> {
constructor(_: never);
}Signature
declare class Positive extends Variance<number, number, never, this> {
constructor(_: never);
}Signature
declare class Uint8 extends Variance<number, number, never, this> {
constructor(_: never);
}Number Filters
This filter checks whether the provided number falls within the specified minimum and maximum values.
Signature
declare function between<S extends Any>(
minimum: number,
maximum: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Ensures that the provided value is a finite number (excluding NaN, +Infinity, and -Infinity).
Signature
declare function finite<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThan
This filter checks whether the provided number is greater than the specified minimum.
Signature
declare function greaterThan<S extends Any>(
exclusiveMinimum: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;greaterThanOrEqualTo
This filter checks whether the provided number is greater than or equal to the specified minimum.
Signature
declare function greaterThanOrEqualTo<S extends Any>(
minimum: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Ensures that the provided value is an integer number (excluding NaN, +Infinity, and -Infinity).
Signature
declare function int<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;This filter checks whether the provided number is less than the specified maximum.
Signature
declare function lessThan<S extends Any>(
exclusiveMaximum: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lessThanOrEqualTo
This schema checks whether the provided number is less than or equal to the specified maximum.
Signature
declare function lessThanOrEqualTo<S extends Any>(
maximum: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;multipleOf
Signature
declare function multipleOf<S extends Any>(
divisor: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function negative<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function nonNaN<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;nonNegative
Signature
declare function nonNegative<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;nonPositive
Signature
declare function nonPositive<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function positive<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends number>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Number Transformations
Clamps a number between a minimum and a maximum value.
Signature
declare function clamp(
minimum: number,
maximum: number,
): <S extends Any, A extends number>(
self: S & Schema<A, Encoded<S>, Context<S>>,
) => transform<S, filter<SchemaClass<A, A, never>>>;NumberFromString
This schema transforms a string into a number by parsing the string using the parse function of the effect/Number module.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
The following special string values are supported: "NaN", "Infinity", "-Infinity".
Signature
declare class NumberFromString extends Variance<number, string, never, this> {
constructor(_: never);
}parseNumber
Transforms a string into a number by parsing the string using the parse function of the effect/Number module.
It returns an error if the value can't be converted (for example when non-numeric characters are provided).
The following special string values are supported: "NaN", "Infinity", "-Infinity".
Signature
declare function parseNumber<S extends Any, A extends string>(
self: S & Schema<A, Encoded<S>, Context<S>>,
): transformOrFail<S, typeof Number$>;Option Transformations
Signature
declare function Option<Value extends Any>(value: Value): Option<Value>;OptionFromNonEmptyTrimmedString
Transforms strings into an Option type, effectively filtering out empty or whitespace-only strings by trimming them and checking their length. Returns none for invalid inputs and some for valid non-empty strings.
Signature
declare class OptionFromNonEmptyTrimmedString extends Variance<
Option<string>,
string,
never,
this
> {
constructor(_: never);
}Example
import { Schema } from "effect"
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)(" a ")) // Option.some("a")
console.log(Schema.decodeSync(Schema.OptionFromNonEmptyTrimmedString)("a")) // Option.some("a")OptionFromNullishOr
Signature
declare function OptionFromNullishOr<Value extends Any>(
value: Value,
onNoneEncoding: null | undefined,
): OptionFromNullishOr<Value>;OptionFromNullOr
Signature
declare function OptionFromNullOr<Value extends Any>(value: Value): OptionFromNullOr<Value>;OptionFromSelf
Signature
declare const OptionFromSelf: <Value extends Any>(value: Value) => OptionFromSelf<Value>;OptionFromUndefinedOr
Signature
declare function OptionFromUndefinedOr<Value extends Any>(
value: Value,
): OptionFromUndefinedOr<Value>;Option Utils
OptionEncoded type
Signature
type OptionEncoded<I> =
| {
readonly _tag: "None";
}
| {
readonly _tag: "Some";
readonly value: I;
};Other
Signature
declare function asSchema<S extends All>(schema: S): Schema<Type<S>, Encoded<S>, Context<S>>;asSerializable
Signature
declare function asSerializable<S extends All>(
serializable: S,
): Serializable<Type<S>, Encoded<S>, Context<S>>;asSerializableWithResult
Signature
declare function asSerializableWithResult<SWR extends All>(
procedure: SWR,
): SerializableWithResult<
Type<SWR>,
Encoded<SWR>,
Context<SWR>,
Success<SWR>,
SuccessEncoded<SWR>,
Failure<SWR>,
FailureEncoded<SWR>,
Context<SWR>
>;asWithResult
Signature
declare function asWithResult<WR extends All>(
withExit: WR,
): WithResult<Success<WR>, SuccessEncoded<WR>, Failure<WR>, FailureEncoded<WR>, Context<WR>>;Signature
declare function element<S extends Any>(self: S): Element<S, "">;encodedBoundSchema
The encodedBoundSchema function is similar to encodedSchema but preserves the refinements up to the first transformation point in the original schema.
Signature
declare function encodedBoundSchema<A, I, R>(schema: Schema<A, I, R>): SchemaClass<I>;encodedSchema
The encodedSchema function allows you to extract the Encoded portion of a schema, creating a new schema that conforms to the properties defined in the original schema without retaining any refinements or transformations that were applied previously.
Signature
declare function encodedSchema<A, I, R>(schema: Schema<A, I, R>): SchemaClass<I>;EnumsDefinition type
Signature
type EnumsDefinition = {
[x: string]: string | number;
};IndexSignature
optionalElement
Signature
declare function optionalElement<S extends Any>(self: S): Element<S, "?">;OptionalOptions type
Signature
type OptionalOptions<A> =
| {
readonly as?: never;
readonly default?: never;
readonly exact?: true;
readonly nullable?: true;
}
| {
readonly as?: never;
readonly default: LazyArg<A>;
readonly exact?: true;
readonly nullable?: true;
}
| {
readonly as: "Option";
readonly default?: never;
readonly exact?: never;
readonly nullable?: never;
readonly onNoneEncoding?: LazyArg<option_.Option<undefined>>;
}
| {
readonly as: "Option";
readonly default?: never;
readonly exact?: never;
readonly nullable: true;
readonly onNoneEncoding?: LazyArg<option_.Option<null | undefined>>;
}
| {
readonly as: "Option";
readonly default?: never;
readonly exact: true;
readonly nullable?: never;
readonly onNoneEncoding?: never;
}
| {
readonly as: "Option";
readonly default?: never;
readonly exact: true;
readonly nullable: true;
readonly onNoneEncoding?: LazyArg<option_.Option<null>>;
}
| undefined;ParseJsonOptions type
Signature
type ParseJsonOptions = {
readonly replacer?: Parameters<typeof JSON.stringify>[1];
readonly reviver?: Parameters<typeof JSON.parse>[1];
readonly space?: Parameters<typeof JSON.stringify>[2];
};PropertySignature
Signature
type Simplify<A> = { [K in keyof A]: A[K] } & {};SimplifyMutable type
Signature
type SimplifyMutable<A> = { [K in keyof A]: A[K] } extends infer B ? B : never;Returns a property signature that represents a tag. A tag is a literal value that is used to distinguish between different types of objects. The tag is optional when using the make method.
See
Signature
declare const tag: <Tag extends LiteralValue>(tag: Tag) => tag<Tag>;Example
import * as assert from "node:assert"
import { Schema } from "effect"
const User = Schema.Struct({
_tag: Schema.tag("User"),
name: Schema.String,
age: Schema.Number,
})
assert.deepStrictEqual(User.make({ name: "John", age: 44 }), {
_tag: "User",
name: "John",
age: 44,
})TaggedRequest
TaggedRequest interface
Signature
interface TaggedRequest<
Tag extends string,
A,
I,
R,
SuccessType,
SuccessEncoded,
FailureType,
FailureEncoded,
ResultR,
>
extends
Request<SuccessType, FailureType>,
SerializableWithResult<
A,
I,
R,
SuccessType,
SuccessEncoded,
FailureType,
FailureEncoded,
ResultR
> {
readonly _tag: Tag;
}TypeLiteral
typeSchema
The typeSchema function allows you to extract the Type portion of a schema, creating a new schema that conforms to the properties defined in the original schema without considering the initial encoding or transformation processes.
Signature
declare function typeSchema<A, I, R>(schema: Schema<A, I, R>): SchemaClass<A>;Primitives
Signature
declare class Any extends Variance<any, any, never, this> {
constructor(_: never);
}BigIntFromSelf
Signature
declare class BigIntFromSelf extends Variance<bigint, bigint, never, this> {
constructor(_: never);
}Signature
declare class Never extends Variance<never, never, never, this> {
constructor(_: never);
}Signature
declare class Null extends Variance<null, null, never, this> {
constructor(_: never);
}SymbolFromSelf
Signature
declare class SymbolFromSelf extends Variance<symbol, symbol, never, this> {
constructor(_: never);
}Signature
declare class Undefined extends Variance<undefined, undefined, never, this> {
constructor(_: never);
}Signature
declare class Unknown extends Variance<unknown, unknown, never, this> {
constructor(_: never);
}Signature
declare class Void extends Variance<void, void, never, this> {
constructor(_: never);
}PropertySignature
Enhances a property signature by specifying a different key for it in the Encoded type.
Signature
declare const fromKey: {
<Key extends PropertyKey>(
key: Key,
): <
TypeToken extends Token,
Type,
EncodedToken extends Token,
Encoded,
HasDefault extends boolean,
R,
>(
self: PropertySignature<TypeToken, Type, PropertyKey, EncodedToken, Encoded, HasDefault, R>,
) => PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;
<
Type,
TypeToken extends Token,
Encoded,
EncodedToken extends Token,
HasDefault extends boolean,
R,
Key extends PropertyKey,
>(
self: PropertySignature<TypeToken, Type, PropertyKey, EncodedToken, Encoded, HasDefault, R>,
key: Key,
): PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;
};FromPropertySignature
Signature
declare class FromPropertySignature extends OptionalType {
constructor(
type: AST,
isOptional: boolean,
isReadonly: boolean,
annotations: Annotations,
fromKey?: PropertyKey,
);
readonly fromKey?: PropertyKey;
readonly isReadonly: boolean;
}makePropertySignature
Signature
declare function makePropertySignature<
TypeToken extends Token,
Type,
Key extends PropertyKey,
EncodedToken extends Token,
Encoded,
HasDefault extends boolean = false,
R = never,
>(ast: AST): PropertySignatureImpl<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;Signature
declare const optional: <S extends All>(self: S) => optional<S>;optionalToOptional
Converts an optional property to another optional property through a transformation Option -> Option.
- decode: - none as argument means the value is missing in the input. - none as return value means the value will be missing in the output. - encode: - none as argument means the value is missing in the input. - none as return value means the value will be missing in the output.
Signature
declare function optionalToOptional<FA, FI, FR, TA, TI, TR>(
from: Schema<FA, FI, FR>,
to: Schema<TA, TI, TR>,
options: {
readonly decode: (o: Option<FA>) => Option<TI>;
readonly encode: (o: Option<TI>) => Option<FA>;
},
): PropertySignature<"?:", TA, never, "?:", FI, false, FR | TR>;optionalToRequired
Converts an optional property to a required one through a transformation Option -> Type.
- decode: none as argument means the value is missing in the input. - encode: none as return value means the value will be missing in the output.
Signature
declare function optionalToRequired<FA, FI, FR, TA, TI, TR>(
from: Schema<FA, FI, FR>,
to: Schema<TA, TI, TR>,
options: {
readonly decode: (o: Option<FA>) => TI;
readonly encode: (ti: TI) => Option<FA>;
},
): PropertySignature<":", TA, never, "?:", FI, false, FR | TR>;optionalWith
Signature
declare const optionalWith: {
<S extends All, Options extends OptionalOptions<Type<S>>>(
options: Options,
): (self: S) => optionalWith<S, Options>;
<S extends All, Options extends OptionalOptions<Type<S>>>(
self: S,
options: Options,
): optionalWith<S, Options>;
};propertySignature
Lifts a Schema into a PropertySignature.
Signature
declare const propertySignature: <S extends All>(self: S) => propertySignature<S>;PropertySignature interface
Signature
interface PropertySignature<
TypeToken extends PropertySignature.Token,
Type,
Key extends PropertyKey,
EncodedToken extends PropertySignature.Token,
Encoded,
HasDefault extends boolean = false,
R = never,
>
extends Variance<Type, Encoded, R>, Pipeable {
readonly _EncodedToken: EncodedToken;
readonly _HasDefault: HasDefault;
readonly _Key: Key;
readonly _TypeToken: TypeToken;
readonly [PropertySignatureTypeId]: null;
readonly ast: AST;
annotations(
annotations: Annotations<Type>,
): PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, HasDefault, R>;
}PropertySignatureDeclaration
Signature
declare class PropertySignatureDeclaration extends OptionalType {
constructor(
type: AST,
isOptional: boolean,
isReadonly: boolean,
annotations: Annotations,
defaultValue: () => unknown | undefined,
);
readonly _tag: "PropertySignatureDeclaration";
readonly defaultValue: () => unknown | undefined;
readonly isReadonly: boolean;
toString(): string;
}PropertySignatureTransformation
Signature
declare class PropertySignatureTransformation {
constructor(
from: FromPropertySignature,
to: ToPropertySignature,
decode: (o: Option<any>) => Option<any>,
encode: (o: Option<any>) => Option<any>,
);
readonly _tag: "PropertySignatureTransformation";
readonly decode: (o: Option<any>) => Option<any>;
readonly encode: (o: Option<any>) => Option<any>;
readonly from: FromPropertySignature;
readonly to: ToPropertySignature;
toString(): string;
}requiredToOptional
Converts an optional property to a required one through a transformation Type -> Option.
- decode: none as return value means the value will be missing in the output. - encode: none as argument means the value is missing in the input.
Signature
declare function requiredToOptional<FA, FI, FR, TA, TI, TR>(
from: Schema<FA, FI, FR>,
to: Schema<TA, TI, TR>,
options: {
readonly decode: (fa: FA) => Option<TI>;
readonly encode: (o: Option<TI>) => FA;
},
): PropertySignature<"?:", TA, never, ":", FI, false, FR | TR>;ToPropertySignature
Signature
declare class ToPropertySignature extends OptionalType {
constructor(
type: AST,
isOptional: boolean,
isReadonly: boolean,
annotations: Annotations,
defaultValue: () => unknown | undefined,
);
readonly defaultValue: () => unknown | undefined;
readonly isReadonly: boolean;
}withConstructorDefault
Enhances a property signature with a default constructor value.
Signature
declare const withConstructorDefault: {
<Type>(
defaultValue: () => NoInfer<Type>,
): <TypeToken extends Token, Key extends PropertyKey, EncodedToken extends Token, Encoded, R>(
self: PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, boolean, R>,
) => PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, true, R>;
<TypeToken extends Token, Type, Key extends PropertyKey, EncodedToken extends Token, Encoded, R>(
self: PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, boolean, R>,
defaultValue: () => NoInfer<Type>,
): PropertySignature<TypeToken, Type, Key, EncodedToken, Encoded, true, R>;
};withDecodingDefault
Enhances a property signature with a default decoding value.
Signature
declare const withDecodingDefault: {
<Type>(
defaultValue: () => NoInfer<Exclude<Type, undefined>>,
): <Key extends PropertyKey, Encoded, R>(
self: PropertySignature<"?:", Type, Key, "?:", Encoded, false, R>,
) => PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, false, R>;
<Type, Key extends PropertyKey, Encoded, R>(
self: PropertySignature<"?:", Type, Key, "?:", Encoded, false, R>,
defaultValue: () => NoInfer<Exclude<Type, undefined>>,
): PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, false, R>;
};withDefaults
Enhances a property signature with a default decoding value and a default constructor value.
Signature
declare const withDefaults: {
<Type>(defaults: {
constructor: () => Types.NoInfer<Exclude<Type, undefined>>;
decoding: () => Types.NoInfer<Exclude<Type, undefined>>;
}): <Key extends PropertyKey, Encoded, R>(
self: PropertySignature<"?:", Type, Key, "?:", Encoded, boolean, R>,
) => PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, true, R>;
<Type, Key extends PropertyKey, Encoded, R>(
self: PropertySignature<"?:", Type, Key, "?:", Encoded, boolean, R>,
defaults: {
constructor: () => Types.NoInfer<Exclude<Type, undefined>>;
decoding: () => Types.NoInfer<Exclude<Type, undefined>>;
},
): PropertySignature<":", Exclude<Type, undefined>, Key, "?:", Encoded, true, R>;
};ReadonlyArray Filters
itemsCount
Signature
declare function itemsCount<S extends Any>(n: number, annotations?: Filter<Type<S>, Type<S>>): <A extends readonly Array<any>>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>Signature
declare function maxItems<S extends Any>(n: number, annotations?: Filter<Type<S>, Type<S>>): <A extends readonly Array<any>>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>Signature
declare function minItems<S extends Any>(n: number, annotations?: Filter<Type<S>, Type<S>>): <A extends readonly Array<any>>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>ReadonlyArray Transformations
getNumberIndexedAccess
Signature
declare function getNumberIndexedAccess<A extends readonly Array<any>, I extends readonly Array<any>, R>(self: Schema<A, I, R>): SchemaClass<A[number], I[number], R>Get the first element of a ReadonlyArray, or None if the array is empty.
Signature
declare function head<S extends Any, A extends readonly Array<unknown>>(self: S & Schema<A, Encoded<S>, Context<S>>): transform<S, OptionFromSelf<SchemaClass<A[number], A[number], never>>>headOrElse
Retrieves the first element of a ReadonlyArray.
If the array is empty, it returns the fallback argument if provided; otherwise, it fails.
Signature
declare const headOrElse: {
<S extends Any, A extends readonly Array<unknown>>(fallback?: LazyArg<A[number]>): (self: S & Schema<A, Encoded<S>, Context<S>>) => transform<S, SchemaClass<A[number], A[number], never>>;
<S extends Any, A extends readonly Array<unknown>>(self: S & Schema<A, Encoded<S>, Context<S>>, fallback?: LazyArg<A[number]>): transform<S, SchemaClass<A[number], A[number], never>>;
}ReadonlyMap
ReadonlyMapFromSelf
Signature
declare const ReadonlyMapFromSelf: <K extends Any, V extends Any>(__namedParameters: {
readonly key: K;
readonly value: V;
}) => ReadonlyMapFromSelf<K, V>;ReadonlyMap Transformations
ReadonlyMap
Signature
declare function ReadonlyMap<K extends Any, V extends Any>(__namedParameters: {
readonly key: K;
readonly value: V;
}): ReadonlyMap$<K, V>;ReadonlyMapFromRecord
Signature
declare function ReadonlyMapFromRecord<KA, KR, VA, VI, VR>(__namedParameters: {
key: Schema<KA, string, KR>;
value: Schema<VA, VI, VR>;
}): SchemaClass<
ReadonlyMap<KA, VA>,
{
[x: string]: VI;
},
KR | VR
>;ReadonlySet
ReadonlySetFromSelf
Signature
declare const ReadonlySetFromSelf: <Value extends Any>(value: Value) => ReadonlySetFromSelf<Value>;ReadonlySet Transformations
ReadonlySet
Signature
declare function ReadonlySet<Value extends Any>(value: Value): ReadonlySet$<Value>;Redacted Constructors
RedactedFromSelf
Signature
declare const RedactedFromSelf: <Value extends Any>(value: Value) => RedactedFromSelf<Value>;Redacted Transformations
Renaming
Signature
declare const rename: {
<
A,
M extends { [K in string | number | symbol]: PropertyKey } & {
[K in string | number | symbol]: never;
},
>(
mapping: M,
): <I, R>(
self: Schema<A, I, R>,
) => SchemaClass<{ [K in string | number | symbol]: Rename<A, M>[K] }, I, R>;
<
A,
I,
R,
M extends { [K in string | number | symbol]: PropertyKey } & {
[K in string | number | symbol]: never;
},
>(
self: Schema<A, I, R>,
mapping: M,
): SchemaClass<{ [K in string | number | symbol]: Rename<A, M>[K] }, I, R>;
};Schema Id
BetweenBigDecimalSchemaId
Signature
declare const BetweenBigDecimalSchemaId: unique symbol;BetweenBigIntSchemaId
Signature
declare const BetweenBigIntSchemaId: unique symbol;BetweenBigIntSchemaId type
Signature
type BetweenBigIntSchemaId = typeof BetweenBigIntSchemaId;BetweenDateSchemaId
Signature
declare const BetweenDateSchemaId: unique symbol;BetweenDurationSchemaId
Signature
declare const BetweenDurationSchemaId: unique symbol;BetweenSchemaId
Signature
declare const BetweenSchemaId: unique symbol;BetweenSchemaId type
Signature
type BetweenSchemaId = typeof BetweenSchemaId;BrandSchemaId
Signature
declare const BrandSchemaId: unique symbol;CapitalizedSchemaId
Signature
declare const CapitalizedSchemaId: unique symbol;DateFromSelfSchemaId
Signature
declare const DateFromSelfSchemaId: unique symbol;DateFromSelfSchemaId type
Signature
type DateFromSelfSchemaId = typeof DateFromSelfSchemaId;EndsWithSchemaId
Signature
declare const EndsWithSchemaId: unique symbol;FiniteSchemaId
Signature
declare const FiniteSchemaId: unique symbol;FiniteSchemaId type
Signature
type FiniteSchemaId = typeof FiniteSchemaId;GreaterThanBigDecimalSchemaId
Signature
declare const GreaterThanBigDecimalSchemaId: unique symbol;GreaterThanBigIntSchemaId
Signature
declare const GreaterThanBigIntSchemaId: unique symbol;GreaterThanBigIntSchemaId type
Signature
type GreaterThanBigIntSchemaId = typeof GreaterThanBigIntSchemaId;GreaterThanDateSchemaId
Signature
declare const GreaterThanDateSchemaId: unique symbol;GreaterThanDurationSchemaId
Signature
declare const GreaterThanDurationSchemaId: unique symbol;GreaterThanOrEqualToBigDecimalSchemaId
Signature
declare const GreaterThanOrEqualToBigDecimalSchemaId: unique symbol;GreaterThanOrEqualToBigIntSchemaId
Signature
declare const GreaterThanOrEqualToBigIntSchemaId: unique symbol;GreaterThanOrEqualToBigIntSchemaId type
Signature
type GreaterThanOrEqualToBigIntSchemaId = typeof GreaterThanOrEqualToBigIntSchemaId;GreaterThanOrEqualToDateSchemaId
Signature
declare const GreaterThanOrEqualToDateSchemaId: unique symbol;GreaterThanOrEqualToDurationSchemaId
Signature
declare const GreaterThanOrEqualToDurationSchemaId: unique symbol;GreaterThanOrEqualToSchemaId
Signature
declare const GreaterThanOrEqualToSchemaId: unique symbol;GreaterThanOrEqualToSchemaId type
Signature
type GreaterThanOrEqualToSchemaId = typeof GreaterThanOrEqualToSchemaId;GreaterThanSchemaId
Signature
declare const GreaterThanSchemaId: unique symbol;GreaterThanSchemaId type
Signature
type GreaterThanSchemaId = typeof GreaterThanSchemaId;IncludesSchemaId
Signature
declare const IncludesSchemaId: unique symbol;InstanceOfSchemaId
Signature
declare const InstanceOfSchemaId: unique symbol;IntSchemaId
Signature
declare const IntSchemaId: unique symbol;IntSchemaId type
Signature
type IntSchemaId = typeof IntSchemaId;ItemsCountSchemaId
Signature
declare const ItemsCountSchemaId: unique symbol;ItemsCountSchemaId type
Signature
type ItemsCountSchemaId = typeof ItemsCountSchemaId;JsonNumberSchemaId
Signature
declare const JsonNumberSchemaId: unique symbol;JsonNumberSchemaId type
Signature
type JsonNumberSchemaId = typeof JsonNumberSchemaId;LengthSchemaId
Signature
declare const LengthSchemaId: unique symbol;LengthSchemaId type
Signature
type LengthSchemaId = typeof LengthSchemaId;LessThanBigDecimalSchemaId
Signature
declare const LessThanBigDecimalSchemaId: unique symbol;LessThanBigIntSchemaId
Signature
declare const LessThanBigIntSchemaId: unique symbol;LessThanBigIntSchemaId type
Signature
type LessThanBigIntSchemaId = typeof LessThanBigIntSchemaId;LessThanDateSchemaId
Signature
declare const LessThanDateSchemaId: unique symbol;LessThanDurationSchemaId
Signature
declare const LessThanDurationSchemaId: unique symbol;LessThanOrEqualToBigDecimalSchemaId
Signature
declare const LessThanOrEqualToBigDecimalSchemaId: unique symbol;LessThanOrEqualToBigIntSchemaId
Signature
declare const LessThanOrEqualToBigIntSchemaId: unique symbol;LessThanOrEqualToBigIntSchemaId type
Signature
type LessThanOrEqualToBigIntSchemaId = typeof LessThanOrEqualToBigIntSchemaId;LessThanOrEqualToDateSchemaId
Signature
declare const LessThanOrEqualToDateSchemaId: unique symbol;LessThanOrEqualToDurationSchemaId
Signature
declare const LessThanOrEqualToDurationSchemaId: unique symbol;LessThanOrEqualToSchemaId
Signature
declare const LessThanOrEqualToSchemaId: unique symbol;LessThanOrEqualToSchemaId type
Signature
type LessThanOrEqualToSchemaId = typeof LessThanOrEqualToSchemaId;LessThanSchemaId
Signature
declare const LessThanSchemaId: unique symbol;LessThanSchemaId type
Signature
type LessThanSchemaId = typeof LessThanSchemaId;LowercasedSchemaId
Signature
declare const LowercasedSchemaId: unique symbol;MaxItemsSchemaId
Signature
declare const MaxItemsSchemaId: unique symbol;MaxItemsSchemaId type
Signature
type MaxItemsSchemaId = typeof MaxItemsSchemaId;MaxLengthSchemaId
Signature
declare const MaxLengthSchemaId: unique symbol;MaxLengthSchemaId type
Signature
type MaxLengthSchemaId = typeof MaxLengthSchemaId;MinItemsSchemaId
Signature
declare const MinItemsSchemaId: unique symbol;MinItemsSchemaId type
Signature
type MinItemsSchemaId = typeof MinItemsSchemaId;MinLengthSchemaId
Signature
declare const MinLengthSchemaId: unique symbol;MinLengthSchemaId type
Signature
type MinLengthSchemaId = typeof MinLengthSchemaId;MultipleOfSchemaId
Signature
declare const MultipleOfSchemaId: unique symbol;NegativeBigDecimalSchemaId
Signature
declare const NegativeBigDecimalSchemaId: unique symbol;NonNaNSchemaId
Signature
declare const NonNaNSchemaId: unique symbol;NonNaNSchemaId type
Signature
type NonNaNSchemaId = typeof NonNaNSchemaId;NonNegativeBigDecimalSchemaId
Signature
declare const NonNegativeBigDecimalSchemaId: unique symbol;NonPositiveBigDecimalSchemaId
Signature
declare const NonPositiveBigDecimalSchemaId: unique symbol;PatternSchemaId
Signature
declare const PatternSchemaId: unique symbol;PositiveBigDecimalSchemaId
Signature
declare const PositiveBigDecimalSchemaId: unique symbol;StartsWithSchemaId
Signature
declare const StartsWithSchemaId: unique symbol;TrimmedSchemaId
Signature
declare const TrimmedSchemaId: unique symbol;ULIDSchemaId
Signature
declare const ULIDSchemaId: unique symbol;UncapitalizedSchemaId
Signature
declare const UncapitalizedSchemaId: unique symbol;UppercasedSchemaId
Signature
declare const UppercasedSchemaId: unique symbol;UUIDSchemaId
Signature
declare const UUIDSchemaId: unique symbol;ValidDateSchemaId
Signature
declare const ValidDateSchemaId: unique symbol;Set
SetFromSelf
Signature
declare const SetFromSelf: <Value extends Any>(value: Value) => SetFromSelf<Value>;SortedSet Transformations
Signature
declare function SortedSet<Value extends Any>(
value: Value,
ordA: Order<Type<Value>>,
): SortedSet<Value>;SortedSetFromSelf
Signature
declare const SortedSetFromSelf: <Value extends Any>(
value: Value,
ordA: Order<Type<Value>>,
ordI: Order<Encoded<Value>>,
) => SortedSetFromSelf<Value>;Standard Schema
standardSchemaV1
Returns a "Standard Schema" object conforming to the [Standard Schema v1](https://standardschema.dev/) specification.
This function creates a schema whose validate method attempts to decode and validate the provided input synchronously. If the underlying Schema includes any asynchronous components (e.g., asynchronous message resolutions or checks), then validation will necessarily return a Promise instead.
Any detected defects will be reported via a single issue containing no path.
Signature
declare function standardSchemaV1<A, I>(
schema: Schema<A, I, never>,
overrideOptions?: ParseOptions,
): any;String Constructors
Capitalized
Signature
declare class Capitalized extends Variance<string, string, never, this> {
constructor(_: never);
}A schema representing a single character.
Signature
declare class Char extends Variance<string, string, never, this> {
constructor(_: never);
}Lowercased
Signature
declare class Lowercased extends Variance<string, string, never, this> {
constructor(_: never);
}NonEmptyString
Signature
declare class NonEmptyString extends Variance<string, string, never, this> {
constructor(_: never);
}NonEmptyTrimmedString
Useful for validating strings that must contain meaningful characters without leading or trailing whitespace.
Signature
declare class NonEmptyTrimmedString extends Variance<string, string, never, this> {
constructor(_: never);
}Example
import { Schema } from "effect"
console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)("")) // Option.none()
console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)(" a ")) // Option.none()
console.log(Schema.decodeOption(Schema.NonEmptyTrimmedString)("a")) // Option.some("a")Signature
declare class Trimmed extends Variance<string, string, never, this> {
constructor(_: never);
}Represents a Universally Unique Lexicographically Sortable Identifier (ULID).
ULIDs are designed to be compact, URL-safe, and ordered, making them suitable for use as identifiers. This schema ensures that the provided string adheres to the standard ULID format.
Signature
declare class ULID extends Variance<string, string, never, this> {
constructor(_: never);
}Uncapitalized
Signature
declare class Uncapitalized extends Variance<string, string, never, this> {
constructor(_: never);
}Uppercased
Signature
declare class Uppercased extends Variance<string, string, never, this> {
constructor(_: never);
}Represents a Universally Unique Identifier (UUID).
This schema ensures that the provided string adheres to the standard UUID format.
Signature
declare class UUID extends Variance<string, string, never, this> {
constructor(_: never);
}String Filters
capitalized
Verifies that a string is capitalized.
Signature
declare function capitalized<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function endsWith<S extends Any>(
endsWith: string,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function includes<S extends Any>(
searchString: string,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function length<S extends Any>(
length:
| number
| {
readonly max: number;
readonly min: number;
},
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;lowercased
Verifies that a string is lowercased.
Signature
declare function lowercased<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function maxLength<S extends Any>(
maxLength: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function minLength<S extends Any>(
minLength: number,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;nonEmptyString
Signature
declare function nonEmptyString<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Signature
declare function pattern<S extends Any>(
regex: RegExp,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;startsWith
Signature
declare function startsWith<S extends Any>(
startsWith: string,
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;Verifies that a string contains no leading or trailing whitespaces.
Note. This combinator does not make any transformations, it only validates. If what you were looking for was a combinator to trim strings, then check out the trim combinator.
Signature
declare function trimmed<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;uncapitalized
Verifies that a string is uncapitalized.
Signature
declare function uncapitalized<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;uppercased
Verifies that a string is uppercased.
Signature
declare function uppercased<S extends Any>(
annotations?: Filter<Type<S>, Type<S>>,
): <A extends string>(self: S & Schema<A, Encoded<S>, Context<S>>) => filter<S>;String Transformations
Capitalize
This schema converts a string to capitalized one.
Signature
declare class Capitalize extends Variance<string, string, never, this> {
constructor(_: never);
}This schema converts a string to lowercase.
Signature
declare class Lowercase extends Variance<string, string, never, this> {
constructor(_: never);
}The ParseJson combinator provides a method to convert JSON strings into the unknown type using the underlying functionality of JSON.parse. It also utilizes JSON.stringify for encoding.
You can optionally provide a ParseJsonOptions to configure both JSON.parse and JSON.stringify executions.
Optionally, you can pass a schema Schema<A, I, R> to obtain an A type instead of unknown.
Signature
declare const parseJson: {
<S extends Any>(
schema: S,
options?: ParseJsonOptions,
): transform<SchemaClass<unknown, string, never>, S>;
(options?: ParseJsonOptions): SchemaClass<unknown, string>;
};Example
import * as assert from "node:assert"
import * as Schema from "effect/Schema"
assert.deepStrictEqual(Schema.decodeUnknownSync(Schema.parseJson())(`{"a":"1"}`), { a: "1" })
assert.deepStrictEqual(
Schema.decodeUnknownSync(Schema.parseJson(Schema.Struct({ a: Schema.NumberFromString })))(
`{"a":"1"}`,
),
{ a: 1 },
)Returns a schema that allows splitting a string into an array of strings.
Signature
declare function split(
separator: string,
): transform<SchemaClass<string, string, never>, Array$<typeof String$>>;StringFromBase64
Decodes a base64 (RFC4648) encoded string into a UTF-8 string.
Signature
declare const StringFromBase64: Schema<string>;StringFromBase64Url
Decodes a base64 (URL) encoded string into a UTF-8 string.
Signature
declare const StringFromBase64Url: Schema<string>;StringFromHex
Decodes a hex encoded string into a UTF-8 string.
Signature
declare const StringFromHex: Schema<string>;StringFromUriComponent
Decodes a URI component encoded string into a UTF-8 string. Can be used to store data in a URL.
Signature
declare const StringFromUriComponent: transformOrFail<
SchemaClass<string, string, never>,
typeof String$,
never
>;Example
import { Schema } from "effect"
const PaginationSchema = Schema.Struct({
maxItemPerPage: Schema.Number,
page: Schema.Number,
})
const UrlSchema = Schema.compose(Schema.StringFromUriComponent, Schema.parseJson(PaginationSchema))
console.log(Schema.encodeSync(UrlSchema)({ maxItemPerPage: 10, page: 1 }))
// Output: %7B%22maxItemPerPage%22%3A10%2C%22page%22%3A1%7DThis schema allows removing whitespaces from the beginning and end of a string.
Signature
declare class Trim extends Variance<string, string, never, this> {
constructor(_: never);
}Uncapitalize
This schema converts a string to uncapitalized one.
Signature
declare class Uncapitalize extends Variance<string, string, never, this> {
constructor(_: never);
}This schema converts a string to uppercase.
Signature
declare class Uppercase extends Variance<string, string, never, this> {
constructor(_: never);
}Struct Transformations
Signature
declare function omit<A, I, Keys extends readonly Array<keyof A & keyof I>>(...keys: Keys): <R>(self: Schema<A, I, R>) => SchemaClass<{ [K in string | number | symbol]: Omit<A, Keys[number]>[K] }, { [K in string | number | symbol]: Omit<I, Keys[number]>[K] }, R>Signature
declare function pick<A, I, Keys extends readonly Array<keyof A & keyof I>>(...keys: Keys): <R>(self: Schema<A, I, R>) => SchemaClass<{ [K in string | number | symbol]: Pick<A, Keys[number]>[K] }, { [K in string | number | symbol]: Pick<I, Keys[number]>[K] }, R>Given a schema Schema<A, I, R> and a key key: K, this function extracts a specific field from the A type, producing a new schema that represents a transformation from the { readonly [key]: I[K] } type to A[K].
Signature
declare const pluck: {
<A, I, K extends string | number | symbol>(
key: K,
): <R>(
schema: Schema<A, I, R>,
) => SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>;
<A, I, R, K extends string | number | symbol>(
schema: Schema<A, I, R>,
key: K,
): SchemaClass<A[K], { [K in string | number | symbol]: Pick<I, K>[K] }, R>;
};Example
import * as Schema from "effect/Schema"
// ---------------------------------------------
// use case: pull out a single field from a
// struct through a transformation
// ---------------------------------------------
const mytable = Schema.Struct({
column1: Schema.NumberFromString,
column2: Schema.Number,
})
// const pullOutColumn: S.Schema<number, {
// readonly column1: string;
// }, never>
const pullOutColumn = mytable.pipe(Schema.pluck("column1"))
console.log(
Schema.decodeUnknownEither(Schema.Array(pullOutColumn))([
{ column1: "1", column2: 100 },
{ column1: "2", column2: 300 },
]),
)
// Output: { _id: 'Either', _tag: 'Right', right: [ 1, 2 ] }Symbol
PropertySignatureTypeId
Signature
declare const PropertySignatureTypeId: unique symbol;PropertySignatureTypeId type
Signature
type PropertySignatureTypeId = typeof PropertySignatureTypeId;RefineSchemaId
Signature
declare const RefineSchemaId: unique symbol;RefineSchemaId type
Signature
type RefineSchemaId = typeof RefineSchemaId;symbolSerializable
Signature
declare const symbolSerializable: unique symbol;symbolWithResult
Signature
declare const symbolWithResult: unique symbol;Signature
declare const TypeId: unique symbol;Signature
type TypeId = typeof TypeId;Template Literal
TemplateLiteral
Signature
declare const TemplateLiteral: <
Params extends readonly [TemplateLiteralParameter, TemplateLiteralParameter],
>(
...__namedParameters: Params
) => TemplateLiteral<GetTemplateLiteralType<Params>>;TemplateLiteralParser
Signature
declare const TemplateLiteralParser: <
Params extends readonly [TemplateLiteralParserParameters, TemplateLiteralParserParameters],
>(
...params: Params
) => TemplateLiteralParser<Params>;TimeZone Constructors
TimeZoneFromSelf
Signature
declare class TimeZoneFromSelf extends Variance<Offset | Named, Offset | Named, never, this> {
constructor(_: never);
}TimeZoneNamedFromSelf
Describes a schema that represents a TimeZone.Named instance.
Signature
declare class TimeZoneNamedFromSelf extends Variance<Named, Named, never, this> {
constructor(_: never);
}TimeZoneOffsetFromSelf
Describes a schema that represents a TimeZone.Offset instance.
Signature
declare class TimeZoneOffsetFromSelf extends Variance<Offset, Offset, never, this> {
constructor(_: never);
}TimeZone Transformations
Defines a schema that attempts to convert a string to a TimeZone using the DateTime.zoneFromString constructor.
Signature
declare class TimeZone extends Variance<Offset | Named, string, never, this> {
constructor(_: never);
}TimeZoneNamed
Defines a schema that attempts to convert a string to a TimeZone.Named instance using the DateTime.zoneUnsafeMakeNamed constructor.
Signature
declare class TimeZoneNamed extends Variance<Named, string, never, this> {
constructor(_: never);
}TimeZoneOffset
Defines a schema that converts a number to a TimeZone.Offset instance using the DateTime.zoneMakeOffset constructor.
Signature
declare class TimeZoneOffset extends Variance<Offset, number, never, this> {
constructor(_: never);
}Transformations
filterEffect
Signature
declare const filterEffect: {
<S extends Any, FD>(
f: (
a: NoInfer<Type<S>>,
options: ParseOptions,
self: Transformation,
) => Effect<FilterReturnType, never, FD>,
): (self: S) => filterEffect<S, FD>;
<S extends Any, RD>(
self: S,
f: (
a: NoInfer<Type<S>>,
options: ParseOptions,
self: Transformation,
) => Effect<FilterReturnType, never, RD>,
): filterEffect<S, RD>;
};Create a new Schema by transforming the input and output of an existing Schema using the provided mapping functions.
Signature
declare const transform: {
<To extends Any, From extends Any>(
to: To,
options:
| {
readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => Encoded<To>;
readonly encode: (toI: Encoded<To>, toA: Type<To>) => Type<From>;
readonly strict?: true;
}
| {
readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => unknown;
readonly encode: (toI: Encoded<To>, toA: Type<To>) => unknown;
readonly strict: false;
},
): (from: From) => transform<From, To>;
<To extends Any, From extends Any>(
from: From,
to: To,
options:
| {
readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => Encoded<To>;
readonly encode: (toI: Encoded<To>, toA: Type<To>) => Type<From>;
readonly strict?: true;
}
| {
readonly decode: (fromA: Type<From>, fromI: Encoded<From>) => unknown;
readonly encode: (toI: Encoded<To>, toA: Type<To>) => unknown;
readonly strict: false;
},
): transform<From, To>;
};transformOrFail
Create a new Schema by transforming the input and output of an existing Schema using the provided decoding functions.
Signature
declare const transformOrFail: {
<To extends Any, From extends Any, RD, RE>(
to: To,
options:
| {
readonly decode: (
fromA: Type<From>,
options: ParseOptions,
ast: Transformation,
fromI: Encoded<From>,
) => Effect<Encoded<To>, ParseIssue, RD>;
readonly encode: (
toI: Encoded<To>,
options: ParseOptions,
ast: Transformation,
toA: Type<To>,
) => Effect<Type<From>, ParseIssue, RE>;
readonly strict?: true;
}
| {
readonly decode: (
fromA: Type<From>,
options: ParseOptions,
ast: Transformation,
fromI: Encoded<From>,
) => Effect<unknown, ParseIssue, RD>;
readonly encode: (
toI: Encoded<To>,
options: ParseOptions,
ast: Transformation,
toA: Type<To>,
) => Effect<unknown, ParseIssue, RE>;
readonly strict: false;
},
): (from: From) => transformOrFail<From, To, RD | RE>;
<To extends Any, From extends Any, RD, RE>(
from: From,
to: To,
options:
| {
readonly decode: (
fromA: Type<From>,
options: ParseOptions,
ast: Transformation,
fromI: Encoded<From>,
) => Effect<Encoded<To>, ParseIssue, RD>;
readonly encode: (
toI: Encoded<To>,
options: ParseOptions,
ast: Transformation,
toA: Type<To>,
) => Effect<Type<From>, ParseIssue, RE>;
readonly strict?: true;
}
| {
readonly decode: (
fromA: Type<From>,
options: ParseOptions,
ast: Transformation,
fromI: Encoded<From>,
) => Effect<unknown, ParseIssue, RD>;
readonly encode: (
toI: Encoded<To>,
options: ParseOptions,
ast: Transformation,
toA: Type<To>,
) => Effect<unknown, ParseIssue, RE>;
readonly strict: false;
},
): transformOrFail<From, To, RD | RE>;
};Uint8Array Constructors
Uint8ArrayFromSelf
Signature
declare class Uint8ArrayFromSelf extends Variance<
Uint8Array<ArrayBufferLike>,
Uint8Array<ArrayBufferLike>,
never,
this
> {
constructor(_: never);
}Uint8Array Transformations
Uint8ArrayFromBase64
Decodes a base64 (RFC4648) encoded string into a Uint8Array.
Signature
declare const Uint8ArrayFromBase64: Schema<Uint8Array, string>;Uint8ArrayFromBase64Url
Decodes a base64 (URL) encoded string into a Uint8Array.
Signature
declare const Uint8ArrayFromBase64Url: Schema<Uint8Array, string>;Uint8ArrayFromHex
Decodes a hex encoded string into a Uint8Array.
Signature
declare const Uint8ArrayFromHex: Schema<Uint8Array, string>;URL Constructors
URLFromSelf
Defines a schema that represents a URL object.
Signature
declare class URLFromSelf extends Variance<URL, URL, never, this> {
constructor(_: never);
}Validation
By default the option exact is set to true.
Signature
declare function asserts<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => asserts u is A;By default the option exact is set to true.
Signature
declare function is<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: number | ParseOptions) => u is A;Signature
declare function validate<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Effect<A, ParseError, R>;validateEither
Signature
declare function validateEither<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Either<A, ParseError>;validateOption
Signature
declare function validateOption<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Option<A>;validatePromise
Signature
declare function validatePromise<A, I>(
schema: Schema<A, I, never>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => Promise<A>;validateSync
Signature
declare function validateSync<A, I, R>(
schema: Schema<A, I, R>,
options?: ParseOptions,
): (u: unknown, overrideOptions?: ParseOptions) => A;
Merges a set of new annotations with existing ones, potentially overwriting any duplicates.