Schema.Struct<{
readonly _tag: Schema.tag<"Reference">
readonly $ref: Schema.String
}>Schema for the Reference representation node.
export const const $Reference: Schema.Struct<{
readonly _tag: Schema.tag<"Reference">
readonly $ref: Schema.String
}>
const $Reference: {
Type: Struct.Type<Fields>;
Encoded: Struct.Encoded<Fields>;
DecodingServices: Struct.DecodingServices<Fields>;
EncodingServices: Struct.EncodingServices<Fields>;
Iso: Struct.Iso<Fields>;
fields: Fields;
mapFields: (f: (fields: { readonly _tag: Schema.tag<'Reference'>; readonly $ref: Schema.String }) => To, options?: { readonly unsafePreserveChecks?: boolean | undefined } | undefined) => Schema.Struct<{ [K in keyof Readonly<To>]: Readonly<To>[K]; }>;
Rebuild: Rebuild;
ast: Ast;
annotate: (annotations: Schema.Annotations.Bottom<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Reference'>; readonly $ref: Schema.String; }, 'Type'>, readonly []>) => Schema.Struct<{ readonly _tag: Schema.tag<'Reference'>; readonly $ref: …;
annotateKey: (annotations: Schema.Annotations.Key<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Reference'>; readonly $ref: Schema.String }, 'Type'>>) => Schema.Struct<{ readonly _tag: Schema.tag<'Reference'>; readonly $ref: Schema.String }>;
check: (checks_0: SchemaAST.Check<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Reference'>; readonly $ref: Schema.String }, 'Type'>>, ...checks: Array<SchemaAST.Check<Schema.Struct.ReadonlySide<{ readonly _tag: Schema.tag<'Reference'>;…;
rebuild: (ast: SchemaAST.Objects) => Schema.Struct<{ readonly _tag: Schema.tag<'Reference'>; readonly $ref: Schema.String }>;
make: (input: { readonly $ref: string; readonly _tag?: 'Reference' | undefined }, options?: MakeOptions) => Struct.ReadonlySide<{ readonly _tag: tag<'Reference'>; readonly $ref: String }, 'Type'>;
makeOption: (input: { readonly $ref: string; readonly _tag?: 'Reference' | undefined }, options?: MakeOptions) => Option_.Option<Struct.ReadonlySide<{ readonly _tag: tag<'Reference'>; readonly $ref: String }, 'Type'>>;
makeEffect: (input: { readonly $ref: string; readonly _tag?: 'Reference' | undefined }, options?: MakeOptions) => Effect.Effect<Struct.ReadonlySide<{ readonly _tag: tag<'Reference'>; readonly $ref: String }, 'Type'>, 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; <…;
}
Schema for the
Reference
representation node.
$Reference = import SchemaSchema.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: Schema.tag<"Reference">(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: Schema.Annotations.Bottom<'Reference', readonly []>) => Schema.withConstructorDefault<Schema.Literal<'Reference'>>;
annotateKey: (annotations: Schema.Annotations.Key<'Reference'>) => Schema.withConstructorDefault<Schema.Literal<'Reference'>>;
check: (checks_0: SchemaAST.Check<'Reference'>, ...checks: Array<SchemaAST.Check<'Reference'>>) => Schema.withConstructorDefault<Schema.Literal<'Reference'>>;
rebuild: (ast: SchemaAST.Literal) => Schema.withConstructorDefault<Schema.Literal<'Reference'>>;
make: (input: 'Reference', options?: MakeOptions) => 'Reference';
makeOption: (input: 'Reference', options?: MakeOptions) => Option_.Option<'Reference'>;
makeEffect: (input: 'Reference', options?: MakeOptions) => Effect.Effect<'Reference', 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: import SchemaSchema.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("Reference"),
$ref: Schema.String(property) $ref: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.String;
rebuild: (ast: SchemaAST.String) => Schema.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; <…;
}
$ref: import SchemaSchema.const String: Stringconst String: {
Rebuild: Rebuild;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Schema.Annotations.Bottom<string, readonly []>) => Schema.String;
annotateKey: (annotations: Schema.Annotations.Key<string>) => Schema.String;
check: (checks_0: SchemaAST.Check<string>, ...checks: Array<SchemaAST.Check<string>>) => Schema.String;
rebuild: (ast: SchemaAST.String) => Schema.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
}).Bottom<unknown, unknown, unknown, unknown, Objects, Struct<{ readonly _tag: tag<"Reference">; readonly $ref: String; }>, unknown, unknown, readonly [], unknown, "readonly", "required", "no-default", "readonly", "required">.annotate(annotations: Schema.Annotations.Bottom<Schema.Struct<Fields extends Schema.Struct.Fields>.ReadonlySide<{
readonly _tag: Schema.tag<"Reference">;
readonly $ref: Schema.String;
}, "Type">, readonly []>): Schema.Struct<{
readonly _tag: Schema.tag<"Reference">;
readonly $ref: Schema.String;
}>
annotate({ Annotations.Bottom<T, TypeParameters extends ReadonlyArray<Constraint>>.identifier?: string | undefinedStable identifier for this schema node.
Details
Identifiers are used by schema tooling, including JSON Schema
generation, to name references. The default formatter also uses
identifier as the expected label for type-level failures, such as
Expected UserId, got null.
identifier does not name a failed filter or refinement. If the base
type matches and a filter fails, put expected or message on the
filter/refinement instead.
identifier: "Reference" })