FormDataType-level representation of FormData.
export interface FormData extends interface instanceOf<T, Iso = T>Creates a schema that validates values using instanceof.
Decoding and encoding pass the value through unchanged.
Example (Defining a schema for a built-in class)
import { Schema } from "effect"
const DateSchema = Schema.instanceOf(Date)
const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
// decoded: Date
Type-level representation returned by
instanceOf
.
instanceOf<module globalThisglobalThis.FormData> {
readonly "Rebuild": FormData
}
/**
* Schema for JavaScript `FormData` objects.
*
* **Details**
*
* The default JSON serializer encodes a `FormData` as an array of `[key, entry]`
* pairs where each entry is tagged as `"String"` or `"File"`.
*
* @category FormData
* @since 4.0.0
*/
export const const FormData: FormDataconst FormData: {
Rebuild: FormData;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.FormData, readonly []>) => FormData;
annotateKey: (annotations: Annotations.Key<globalThis.FormData>) => FormData;
check: (checks_0: SchemaAST.Check<globalThis.FormData>, ...checks: Array<SchemaAST.Check<globalThis.FormData>>) => FormData;
rebuild: (ast: SchemaAST.Declaration) => FormData;
make: (input: globalThis.FormData, options?: MakeOptions) => globalThis.FormData;
makeOption: (input: globalThis.FormData, options?: MakeOptions) => Option_.Option<globalThis.FormData>;
makeEffect: (input: globalThis.FormData, options?: MakeOptions) => Effect.Effect<globalThis.FormData, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
FormData
.
Schema for JavaScript FormData objects.
Details
The default JSON serializer encodes a FormData as an array of [key, entry]
pairs where each entry is tagged as "String" or "File".
FormData: FormData = function instanceOf<
C extends abstract new (...args: any) => any,
Iso = InstanceType<C>
>(
constructor: C,
annotations?:
| Annotations.Declaration<InstanceType<C>>
| undefined
): instanceOf<InstanceType<C>, Iso>
Creates a schema that validates values using instanceof.
Decoding and encoding pass the value through unchanged.
Example (Defining a schema for a built-in class)
import { Schema } from "effect"
const DateSchema = Schema.instanceOf(Date)
const decoded = Schema.decodeUnknownSync(DateSchema)(new Date("2024-01-01"))
// decoded: Date
instanceOf(module globalThisglobalThis.var FormData: {
new (
form?: HTMLFormElement,
submitter?: HTMLElement | null
): globalThis.FormData
prototype: globalThis.FormData
}
The FormData interface provides a way to construct a set of key/value pairs representing form fields and their values, which can be sent using the Window/fetch, XMLHttpRequest.send() or navigator.sendBeacon() methods.
FormData, {
Annotations.Declaration<globalThis.FormData, readonly []>.typeConstructor?: {
readonly [key: string]: unknown;
readonly _tag: string;
} | undefined
typeConstructor: {
_tag: string_tag: "FormData"
},
Annotations.Declaration<globalThis.FormData, readonly []>.generation?: {
readonly runtime: string;
readonly Type: string;
readonly Encoded?: string | undefined;
readonly importDeclaration?: string | undefined;
} | undefined
generation: {
runtime: stringruntime: `Schema.FormData`,
type Type: stringType: `globalThis.FormData`
},
Annotations.Augment.expected?: string | undefinedHuman-readable description of what a value is expected to satisfy.
Details
For filter and refinement failures, the default formatter uses
message first, then expected, and finally falls back to <filter>.
Use this to name a failed filter in the default message:
Expected <expected>, got <actual>.
expected: "FormData",
Annotations.Declaration<globalThis.FormData, readonly []>.toCodecJson?: ((typeParameters: readonly []) => SchemaAST.Link) | undefinedtoCodecJson: () =>
function link<T>(): <
To extends Constraint
>(
encodeTo: To,
transformation: {
readonly decode: SchemaGetter.Getter<
T,
NoInfer<To["Type"]>
>
readonly encode: SchemaGetter.Getter<
NoInfer<To["Type"]>,
T
>
}
) => SchemaAST.Link
Constructs an SchemaAST.Link that describes how a value of type T encodes to and decodes from a To schema.
Used when building low-level AST transformations that bridge two schema types.
link<module globalThisglobalThis.FormData>()(
const ArraySchema: ArrayLambda
<Tuple<readonly [String, Union<readonly [Struct<{
readonly _tag: tag<"String">;
readonly value: String;
}>, Struct<{
readonly _tag: tag<"File">;
readonly value: File;
}>]>]>>(self: Tuple<readonly [String, Union<readonly [Struct<{
readonly _tag: tag<"String">;
readonly value: String;
}>, Struct<{
readonly _tag: tag<"File">;
readonly value: File;
}>]>]>) => $Array<Tuple<readonly [String, Union<readonly [Struct<{
readonly _tag: tag<"String">;
readonly value: String;
}>, Struct<...>]>]>>
ArraySchema(
function Tuple<
Elements extends ReadonlyArray<Constraint>
>(elements: Elements): Tuple<Elements>
Defines a fixed-length tuple schema from an array of element schemas.
Example (Defining a pair of string and number)
import { Schema } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const pair = Schema.decodeUnknownSync(schema)(["hello", 42])
console.log(pair)
// [ 'hello', 42 ]
Tuple([
const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String,
function Union<
Members extends ReadonlyArray<Constraint>
>(
members: Members,
options?: { mode?: "anyOf" | "oneOf" }
): Union<Members>
Creates a union schema from an array of member schemas. Members are tested in
order; the first match is returned.
Details
Optionally, specify mode:
"anyOf" (default) — matches if any member matches.
"oneOf" — matches if exactly one member matches.
Example (Defining a string or number union)
import { Schema } from "effect"
const schema = Schema.Union([Schema.String, Schema.Number])
Schema.decodeUnknownSync(schema)("hello") // "hello"
Schema.decodeUnknownSync(schema)(42) // 42
Union([
function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({ _tag: tag<"String">(property) _tag: {
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<'String', readonly []>) => withConstructorDefault<Literal<'String'>>;
annotateKey: (annotations: Annotations.Key<'String'>) => withConstructorDefault<Literal<'String'>>;
check: (checks_0: SchemaAST.Check<'String'>, ...checks: Array<SchemaAST.Check<'String'>>) => withConstructorDefault<Literal<'String'>>;
rebuild: (ast: SchemaAST.Literal) => withConstructorDefault<Literal<'String'>>;
make: (input: 'String', options?: MakeOptions) => 'String';
makeOption: (input: 'String', options?: MakeOptions) => Option_.Option<'String'>;
makeEffect: (input: 'String', options?: MakeOptions) => Effect.Effect<'String', SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
_tag: function tag<
Tag extends SchemaAST.LiteralValue
>(literal: Tag): tag<Tag>
Combines a
Literal
schema with
withConstructorDefault
, making it ideal
for discriminator fields in tagged unions. When constructing via make, the
_tag field can be omitted and will be filled automatically.
Example (Defining a discriminated union tag)
import { Schema } from "effect"
const A = Schema.Struct({ _tag: Schema.tag("A"), value: Schema.Number })
// _tag is optional in make, auto-filled to "A"
const a = A.make({ value: 42 })
// a: { _tag: "A", value: 42 }
tag("String"), value: String(property) value: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
value: const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<string, readonly []>) => String;
annotateKey: (annotations: Annotations.Key<string>) => String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => String;
rebuild: (ast: SchemaAST.String) => String;
make: (input: string, options?: MakeOptions) => string;
makeOption: (input: string, options?: MakeOptions) => Option_.Option<string>;
makeEffect: (input: string, options?: MakeOptions) => Effect.Effect<string, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
String
.
Schema for string values. Validates that the input is typeof "string".
String }),
function Struct<
Fields extends Struct.Fields
>(fields: Fields): Struct<Fields>
Defines a struct schema from a map of field schemas.
Details
Each field value is a schema. Use
optionalKey
or
optional
to
mark fields as optional, and
mutableKey
to mark them as mutable.
The resulting schema's Type is a readonly object type with the fields'
decoded types. The Encoded form mirrors the field schemas' encoded types.
Example (Defining a basic struct)
import { Schema } from "effect"
const Person = Schema.Struct({
name: Schema.String,
age: Schema.Number,
email: Schema.optionalKey(Schema.String)
})
// { readonly name: string; readonly age: number; readonly email?: string }
type Person = typeof Person.Type
const alice = Schema.decodeUnknownSync(Person)({ name: "Alice", age: 30 })
console.log(alice)
// { name: 'Alice', age: 30 }
Struct({ _tag: tag<"File">(property) _tag: {
Type: S["Type"];
Encoded: S["Encoded"];
DecodingServices: S["DecodingServices"];
EncodingServices: S["EncodingServices"];
Iso: S["Iso"];
schema: S;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Annotations.Bottom<'File', readonly []>) => withConstructorDefault<Literal<'File'>>;
annotateKey: (annotations: Annotations.Key<'File'>) => withConstructorDefault<Literal<'File'>>;
check: (checks_0: SchemaAST.Check<'File'>, ...checks: Array<SchemaAST.Check<'File'>>) => withConstructorDefault<Literal<'File'>>;
rebuild: (ast: SchemaAST.Literal) => withConstructorDefault<Literal<'File'>>;
make: (input: 'File', options?: MakeOptions) => 'File';
makeOption: (input: 'File', options?: MakeOptions) => Option_.Option<'File'>;
makeEffect: (input: 'File', options?: MakeOptions) => Effect.Effect<'File', SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
_tag: function tag<
Tag extends SchemaAST.LiteralValue
>(literal: Tag): tag<Tag>
Combines a
Literal
schema with
withConstructorDefault
, making it ideal
for discriminator fields in tagged unions. When constructing via make, the
_tag field can be omitted and will be filled automatically.
Example (Defining a discriminated union tag)
import { Schema } from "effect"
const A = Schema.Struct({ _tag: Schema.tag("A"), value: Schema.Number })
// _tag is optional in make, auto-filled to "A"
const a = A.make({ value: 42 })
// a: { _tag: "A", value: 42 }
tag("File"), value: File(property) value: {
Rebuild: File;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.File, readonly []>) => File;
annotateKey: (annotations: Annotations.Key<globalThis.File>) => File;
check: (checks_0: SchemaAST.Check<globalThis.File>, ...checks: Array<SchemaAST.Check<globalThis.File>>) => File;
rebuild: (ast: SchemaAST.Declaration) => File;
make: (input: globalThis.File, options?: MakeOptions) => globalThis.File;
makeOption: (input: globalThis.File, options?: MakeOptions) => Option_.Option<globalThis.File>;
makeEffect: (input: globalThis.File, options?: MakeOptions) => Effect.Effect<globalThis.File, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
value: const File: Fileconst File: {
Rebuild: File;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<globalThis.File, readonly []>) => File;
annotateKey: (annotations: Annotations.Key<globalThis.File>) => File;
check: (checks_0: SchemaAST.Check<globalThis.File>, ...checks: Array<SchemaAST.Check<globalThis.File>>) => File;
rebuild: (ast: SchemaAST.Declaration) => File;
make: (input: globalThis.File, options?: MakeOptions) => globalThis.File;
makeOption: (input: globalThis.File, options?: MakeOptions) => Option_.Option<globalThis.File>;
makeEffect: (input: globalThis.File, options?: MakeOptions) => Effect.Effect<globalThis.File, SchemaError, never>;
pipe: { <A>(this: A): A; <A, B = never>(this: A, ab: (_: A) => B): B; <A, B = never, C = never>(this: A, ab: (_: A) => B, bc: (_: B) => C): C; <A, B = never, C = never, D = never>(this: A, ab: (_: A) => B, bc: (_: B) => C, cd: (_: C) => D): D; <…;
}
Type-level representation of
File
.
Schema for JavaScript File objects.
Details
The default JSON serializer encodes a File as { data, type, name, lastModified }
where data is base64-encoded.
File })
])
])
),
import SchemaTransformationSchemaTransformation.function transformOrFail<
T,
E,
RD = never,
RE = never
>(options: {
readonly decode: (
e: E,
options: SchemaAST.ParseOptions
) => Effect.Effect<T, SchemaIssue.Issue, RD>
readonly encode: (
t: T,
options: SchemaAST.ParseOptions
) => Effect.Effect<E, SchemaIssue.Issue, RE>
}): Transformation<T, E, RD, RE>
Creates a Transformation from effectful decode and encode functions that
can fail with Issue.
When to use
Use when you need a schema transformation that may fail or require Effect
services.
Details
- Each function receives the input value and
ParseOptions.
- Must return an
Effect that succeeds with the output or fails with Issue.
- Skips
None inputs (missing keys) — functions are only called on present values.
Example (Parsing a date string that can fail)
import { Effect, Option, Schema, SchemaIssue, SchemaTransformation } from "effect"
const DateFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Date,
SchemaTransformation.transformOrFail({
decode: (s) => {
const d = new Date(s)
return isNaN(d.getTime())
? Effect.fail(new SchemaIssue.InvalidValue(Option.some(s), { message: "Invalid date" }))
: Effect.succeed(d)
},
encode: (d) => Effect.succeed(d.toISOString())
})
)
)
transformOrFail({
decode: (
e: NoInfer<
readonly (readonly [
string,
(
| Struct.ReadonlySide<
{
readonly _tag: tag<"String">
readonly value: String
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: tag<"File">
readonly value: File
},
"Type"
>
)
])[]
>,
options: SchemaAST.ParseOptions
) => Effect.Effect<
globalThis.FormData,
SchemaIssue.Issue,
never
>
decode: (e: NoInfer<
readonly (readonly [
string,
(
| Struct.ReadonlySide<
{
readonly _tag: tag<"String">
readonly value: String
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: tag<"File">
readonly value: File
},
"Type"
>
)
])[]
>
e) => {
const const out: globalThis.FormDataout = new module globalThisglobalThis.var FormData: new (
form?: HTMLFormElement,
submitter?: HTMLElement | null
) => globalThis.FormData
The FormData interface provides a way to construct a set of key/value pairs representing form fields and their values, which can be sent using the Window/fetch, XMLHttpRequest.send() or navigator.sendBeacon() methods.
FormData()
for (const [const key: stringkey, const entry:
| Struct.ReadonlySide<
{
readonly _tag: tag<"String">
readonly value: String
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: tag<"File">
readonly value: File
},
"Type"
>
entry] of e: readonly (readonly [
string,
(
| Struct.ReadonlySide<
{
readonly _tag: tag<"String">
readonly value: String
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: tag<"File">
readonly value: File
},
"Type"
>
)
])[]
e) {
const out: globalThis.FormDataout.FormData.append(name: string, value: string | Blob): void (+2 overloads)The append() method of the FormData interface appends a new value onto an existing key inside a FormData object, or adds the key if it does not already exist.
append(const key: stringkey, const entry:
| Struct.ReadonlySide<
{
readonly _tag: tag<"String">
readonly value: String
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: tag<"File">
readonly value: File
},
"Type"
>
entry.value: string | globalThis.Filevalue)
}
return import EffectEffect.succeed(const out: globalThis.FormDataout)
},
encode: (
t: globalThis.FormData,
options: SchemaAST.ParseOptions
) => Effect.Effect<
NoInfer<
readonly (readonly [
string,
(
| Struct.ReadonlySide<
{
readonly _tag: tag<"String">
readonly value: String
},
"Type"
>
| Struct.ReadonlySide<
{
readonly _tag: tag<"File">
readonly value: File
},
"Type"
>
)
])[]
>,
SchemaIssue.Issue,
never
>
encode: (formData: globalThis.FormDataformData) => {
return import EffectEffect.succeed(
module globalThisglobalThis.var Array: ArrayConstructorArray.ArrayConstructor.from<[string, FormDataEntryValue]>(iterable: Iterable<[string, FormDataEntryValue]> | ArrayLike<[string, FormDataEntryValue]>): [string, FormDataEntryValue][] (+3 overloads)Creates an array from an iterable object.
from(formData: globalThis.FormDataformData.FormData.entries(): FormDataIterator<[string, FormDataEntryValue]>Returns an array of key, value pairs for every entry in the list.
entries()).Array<[string, FormDataEntryValue]>.map<readonly [string, {
readonly _tag: "String";
readonly value: string;
}] | readonly [string, {
readonly _tag: "File";
readonly value: globalThis.File;
}]>(callbackfn: (value: [string, FormDataEntryValue], index: number, array: [string, FormDataEntryValue][]) => readonly [string, {
readonly _tag: "String";
readonly value: string;
}] | readonly [string, {
readonly _tag: "File";
readonly value: globalThis.File;
}], thisArg?: any): (readonly [string, {
readonly _tag: "String";
readonly value: string;
}] | readonly [string, {
readonly _tag: "File";
readonly value: globalThis.File;
}])[]
Calls a defined callback function on each element of an array, and returns an array that contains the results.
map(([key: stringkey, value: FormDataEntryValuevalue]) => {
if (typeof value: FormDataEntryValuevalue === "string") {
return [key: stringkey, { _tag: "String"_tag: "String", value: stringvalue }] as type const = readonly [string, {
readonly _tag: "String";
readonly value: string;
}]
const
} else {
return [key: stringkey, { _tag: "File"_tag: "File", value: globalThis.Filevalue }] as type const = readonly [string, {
readonly _tag: "File";
readonly value: globalThis.File;
}]
const
}
})
)
}
})
)
})