TimeZoneNamedFromStringType-level representation of TimeZoneNamedFromString.
export interface TimeZoneNamedFromString extends interface decodeTo<To extends Constraint, From extends Constraint, RD = never, RE = never>Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
Type-level representation returned by
decodeTo
.
decodeTo<TimeZoneNamed, String> {
readonly "Rebuild": TimeZoneNamedFromString
}
/**
* Schema that parses an IANA time zone identifier string into a `DateTime.TimeZone.Named`.
*
* **Details**
*
* Decoding:
* - A `string` is decoded as a `DateTime.TimeZone.Named`.
*
* Encoding:
* - A `DateTime.TimeZone.Named` is encoded as a `string`.
*
* @category DateTime
* @since 4.0.0
*/
export const const TimeZoneNamedFromString: TimeZoneNamedFromStringconst TimeZoneNamedFromString: {
Rebuild: TimeZoneNamedFromString;
Type: To["Type"];
Encoded: From["Encoded"];
DecodingServices: To["DecodingServices"] | From["DecodingServices"] | RD;
EncodingServices: To["EncodingServices"] | From["EncodingServices"] | RE;
Iso: To["Iso"];
from: From;
to: To;
ast: Ast;
annotate: (annotations: Annotations.Bottom<DateTime.TimeZone.Named, readonly []>) => TimeZoneNamedFromString;
annotateKey: (annotations: Annotations.Key<DateTime.TimeZone.Named>) => TimeZoneNamedFromString;
check: (checks_0: SchemaAST.Check<DateTime.TimeZone.Named>, ...checks: Array<SchemaAST.Check<DateTime.TimeZone.Named>>) => TimeZoneNamedFromString;
rebuild: (ast: SchemaAST.Declaration) => TimeZoneNamedFromString;
make: (input: DateTime.TimeZone.Named, options?: MakeOptions) => DateTime.TimeZone.Named;
makeOption: (input: DateTime.TimeZone.Named, options?: MakeOptions) => Option_.Option<DateTime.TimeZone.Named>;
makeEffect: (input: DateTime.TimeZone.Named, options?: MakeOptions) => Effect.Effect<DateTime.TimeZone.Named, 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
TimeZoneNamedFromString
.
Schema that parses an IANA time zone identifier string into a DateTime.TimeZone.Named.
Details
Decoding:
- A
string is decoded as a DateTime.TimeZone.Named.
Encoding:
- A
DateTime.TimeZone.Named is encoded as a string.
TimeZoneNamedFromString: TimeZoneNamedFromString = const TimeZoneNamedString: Stringconst TimeZoneNamedString: {
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; <…;
}
TimeZoneNamedString.pipe(
function decodeTo<TimeZoneNamed, Constraint, never, never>(to: TimeZoneNamed, transformation: {
readonly decode: SchemaGetter.Getter<DateTime.TimeZone.Named, unknown, never>;
readonly encode: SchemaGetter.Getter<unknown, DateTime.TimeZone.Named, never>;
}): (from: Constraint) => decodeTo<TimeZoneNamed, Constraint, never, never> (+1 overload)
Creates a schema that transforms from a source schema to a target schema.
When to use
Use when decoding should change the schema's decoded type or encoded shape,
with an optional custom bidirectional transformation.
Details
Call it with the target schema to and then pipe the source schema from
into the returned function. The resulting schema decodes from
From["Encoded"] to To["Type"] and encodes from To["Type"] back to
From["Encoded"].
When no transformation is provided, SchemaTransformation.passthrough() is
used, so From["Type"] must already be compatible with To["Encoded"].
The resulting schema combines decoding and encoding services from both
schemas and any custom transformation.
Gotchas
In a custom transformation, decode maps From["Type"] to To["Encoded"]
and is used on the encoding path, while encode maps To["Encoded"] to
From["Type"] and is used on the decoding path.
Example (Transforming strings to numbers with a schema transformation)
import { Schema, SchemaGetter } from "effect"
const NumberFromString = Schema.String.pipe(
Schema.decodeTo(
Schema.Number,
{
decode: SchemaGetter.transform((s) => Number(s)),
encode: SchemaGetter.transform((n) => String(n))
}
)
)
const result = Schema.decodeUnknownSync(NumberFromString)("123")
// result: 123
decodeTo(const TimeZoneNamed: TimeZoneNamedconst TimeZoneNamed: {
Rebuild: TimeZoneNamed;
Iso: Iso;
ast: Ast;
Type: T;
Encoded: E;
DecodingServices: RD;
EncodingServices: RE;
annotate: (annotations: Annotations.Bottom<DateTime.TimeZone.Named, readonly []>) => TimeZoneNamed;
annotateKey: (annotations: Annotations.Key<DateTime.TimeZone.Named>) => TimeZoneNamed;
check: (checks_0: SchemaAST.Check<DateTime.TimeZone.Named>, ...checks: Array<SchemaAST.Check<DateTime.TimeZone.Named>>) => TimeZoneNamed;
rebuild: (ast: SchemaAST.Declaration) => TimeZoneNamed;
make: (input: DateTime.TimeZone.Named, options?: MakeOptions) => DateTime.TimeZone.Named;
makeOption: (input: DateTime.TimeZone.Named, options?: MakeOptions) => Option_.Option<DateTime.TimeZone.Named>;
makeEffect: (input: DateTime.TimeZone.Named, options?: MakeOptions) => Effect.Effect<DateTime.TimeZone.Named, 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
TimeZoneNamed
.
Schema for DateTime.TimeZone.Named values.
Details
Default JSON serializer:
- encodes
DateTime.TimeZone.Named as a string (IANA time zone identifier)
TimeZoneNamed, import SchemaTransformationSchemaTransformation.const timeZoneNamedFromString: Transformation<
DateTime.TimeZone.Named,
string
>
const timeZoneNamedFromString: {
_tag: 'Transformation';
decode: SchemaGetter.Getter<T, E, RD>;
encode: SchemaGetter.Getter<E, T, RE>;
flip: () => SchemaTransformation.Transformation<string, DateTime.TimeZone.Named, never, never>;
compose: (other: SchemaTransformation.Transformation<T2, DateTime.TimeZone.Named, RD2, RE2>) => SchemaTransformation.Transformation<T2, string, RD2, RE2>;
}
Decodes an IANA time-zone identifier string into a
DateTime.TimeZone.Named and encodes a named time zone back to its id.
When to use
Use when you need a schema transformation to accept only IANA time-zone
identifier strings and produce DateTime.TimeZone.Named values.
Details
Decode fails with InvalidValue when the string is not a valid IANA time-zone
identifier.
timeZoneNamedFromString)
)