Enum<A>Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
Example (Defining a direction enum)
import { Schema } from "effect"
enum Direction {
Up = "Up",
Down = "Down"
}
const schema = Schema.Enum(Direction)
// accepts "Up" or "Down"export interface interface Enum<A extends { [x: string]: string | number; }>Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
Example (Defining a direction enum)
import { Schema } from "effect"
enum Direction {
Up = "Up",
Down = "Down"
}
const schema = Schema.Enum(Direction)
// accepts "Up" or "Down"
Type-level representation returned by
Enum
.
Enum<function (type parameter) A in Enum<A extends { [x: string]: string | number; }>A extends { [x: stringx: string]: string | number }>
extends interface Bottom<out T, out E, out RD, out RE, out Ast extends SchemaAST.AST, out Rebuild extends Top, out TypeMakeIn = T, out Iso = T, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], out TypeMake = TypeMakeIn, out TypeMutability extends Mutability = "readonly", out TypeOptionality extends Optionality = "required", out TypeConstructorDefault extends ConstructorDefault = "no-default", out EncodedMutability extends Mutability = "readonly", out EncodedOptionality extends Optionality = "required">The fully-parameterized base interface for all schemas. Exposes all 14 type
parameters controlling type inference, mutability, optionality, services, and
transformation behavior.
When to use
Use when you are writing advanced generic schema utilities or performing
schema introspection.
Bottom<function (type parameter) A in Enum<A extends { [x: string]: string | number; }>A[keyof function (type parameter) A in Enum<A extends { [x: string]: string | number; }>A], function (type parameter) A in Enum<A extends { [x: string]: string | number; }>A[keyof function (type parameter) A in Enum<A extends { [x: string]: string | number; }>A], never, never, import SchemaASTSchemaAST.class Enumclass Enum {
_tag: 'Enum';
enums: ReadonlyArray<readonly [string, string | number]>;
getParser: () => SchemaParser.Parser;
toCodecStringTree: () => AST;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node representing a TypeScript enum.
Details
Holds enums as an array of [name, value] pairs where values are
string | number. Parsing succeeds when the input matches any enum value.
Enum, interface Enum<A extends { [x: string]: string | number; }>Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
Example (Defining a direction enum)
import { Schema } from "effect"
enum Direction {
Up = "Up",
Down = "Down"
}
const schema = Schema.Enum(Direction)
// accepts "Up" or "Down"
Type-level representation returned by
Enum
.
Enum<function (type parameter) A in Enum<A extends { [x: string]: string | number; }>A>>
{
readonly Enum<A extends { [x: string]: string | number; }>.enums: A extends { [x: string]: string | number; }enums: function (type parameter) A in Enum<A extends { [x: string]: string | number; }>A
}
/**
* Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
*
* **Example** (Defining a direction enum)
*
* ```ts
* import { Schema } from "effect"
*
* enum Direction {
* Up = "Up",
* Down = "Down"
* }
*
* const schema = Schema.Enum(Direction)
* // accepts "Up" or "Down"
* ```
*
* @category constructors
* @since 4.0.0
*/
export function function Enum<
A extends { [x: string]: string | number }
>(enums: A): Enum<A>
Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
Example (Defining a direction enum)
import { Schema } from "effect"
enum Direction {
Up = "Up",
Down = "Down"
}
const schema = Schema.Enum(Direction)
// accepts "Up" or "Down"
Enum<function (type parameter) A in Enum<A extends {
[x: string]: string | number;
}>(enums: A): Enum<A>
A extends { [x: stringx: string]: string | number }>(enums: A extends { [x: string]: string | number; }enums: function (type parameter) A in Enum<A extends {
[x: string]: string | number;
}>(enums: A): Enum<A>
A): interface Enum<A extends { [x: string]: string | number; }>Creates a schema from a TypeScript enum object. Validates that the input is one of the enum's values.
Example (Defining a direction enum)
import { Schema } from "effect"
enum Direction {
Up = "Up",
Down = "Down"
}
const schema = Schema.Enum(Direction)
// accepts "Up" or "Down"
Type-level representation returned by
Enum
.
Enum<function (type parameter) A in Enum<A extends {
[x: string]: string | number;
}>(enums: A): Enum<A>
A> {
return const make: <S extends Constraint>(
ast: S["ast"],
options?: object
) => S
Creates a schema from an AST (Abstract Syntax Tree) node.
Details
This is the fundamental constructor for all schemas in the Effect Schema
library. It takes an AST node and wraps it in a fully-typed schema that
preserves all type information and provides the complete schema API.
The make function is used internally to create all primitive schemas like
String, Number, Boolean, etc., as well as more complex schemas. It's
the bridge between the untyped AST representation and the strongly-typed
schema.
make(
new import SchemaASTSchemaAST.constructor Enum(enums: ReadonlyArray<readonly [string, string | number]>, annotations?: Annotations.Annotations, checks?: SchemaAST.Checks, encoding?: SchemaAST.Encoding, context?: SchemaAST.Context): SchemaAST.EnumAST node representing a TypeScript enum.
Details
Holds enums as an array of [name, value] pairs where values are
string | number. Parsing succeeds when the input matches any enum value.
Enum(
var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.keys(o: {}): string[] (+1 overload)Returns the names of the enumerable string properties and methods of an object.
keys(enums: A extends { [x: string]: string | number; }enums).Array<string>.filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[] (+1 overload)Returns the elements of an array that meet the condition specified in a callback function.
filter(
(key: stringkey) => typeof enums: A extends { [x: string]: string | number; }enums[enums: A extends { [x: string]: string | number; }enums[key: stringkey]] !== "number"
).Array<string>.map<[string, string | number]>(callbackfn: (value: string, index: number, array: string[]) => [string, string | number], thisArg?: any): [string, string | number][]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((key: stringkey) => [key: stringkey, enums: A extends { [x: string]: string | number; }enums[key: stringkey]])
),
{ enums: A extends { [x: string]: string | number; }enums }
)
}