TemplateLiteralParser<Parts>Schema for parsing matched template literal strings into typed tuple parts.
When to use
Use to validate a template literal string and decode the matched parts into typed values.
Details
Unlike TemplateLiteral, this schema decodes the matched string into a readonly tuple with one element per schema part. Checks on string, number, and bigint schema parts are applied while matching each segment.
Example (Parsing path parameters)
import { Schema } from "effect"
const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
// decodes "/user/42" => readonly ["/user/", 42]export declare namespace TemplateLiteralParser {
/**
* Computes the decoded tuple type produced by `TemplateLiteralParser`.
*
* **Details**
*
* Literal parts contribute their literal value to the tuple. Schema parts
* contribute their decoded `Type`.
*
* @category utility types
* @since 3.10.0
*/
export type type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts> = Parts extends readonly [infer Head, ...infer Tail] ? readonly [Head extends TemplateLiteral.LiteralPart ? Head : Head extends ConstraintDecoder<infer T, unknown> ? T : never, ...Type<Tail>] : []Computes the decoded tuple type produced by TemplateLiteralParser.
Details
Literal parts contribute their literal value to the tuple. Schema parts
contribute their decoded Type.
Type<function (type parameter) Parts in type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts>Parts> = function (type parameter) Parts in type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts>Parts extends readonly [infer function (type parameter) HeadHead, ...infer function (type parameter) TailTail] ? readonly [
function (type parameter) HeadHead extends TemplateLiteral.type TemplateLiteral<Parts extends TemplateLiteral.Parts>.LiteralPart = string | number | bigintLiteral value that can be used directly as a part of a TemplateLiteral.
LiteralPart ? function (type parameter) HeadHead :
function (type parameter) HeadHead extends interface ConstraintDecoder<out T, out RD = never>Lightweight structural constraint for APIs that need decoder type views but
do not need the full schema protocol.
When to use
Use when you need to preserve a schema's decoded type and decoding services,
but the API does not constrain the encoded type, encoding services, or call
schema methods such as annotate, check, rebuild, make, or
makeEffect.
ConstraintDecoder<infer function (type parameter) TT, unknown> ? function (type parameter) TT
: never,
...type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts> = Parts extends readonly [infer Head, ...infer Tail] ? readonly [Head extends TemplateLiteral.LiteralPart ? Head : Head extends ConstraintDecoder<infer T, unknown> ? T : never, ...Type<Tail>] : []Computes the decoded tuple type produced by TemplateLiteralParser.
Details
Literal parts contribute their literal value to the tuple. Schema parts
contribute their decoded Type.
Type<function (type parameter) TailTail>
]
: []
}
/**
* Type-level representation returned by {@link TemplateLiteralParser}.
*
* @category models
* @since 3.10.0
*/
export interface interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Schema for parsing matched template literal strings into typed tuple parts.
When to use
Use to validate a template literal string and decode the matched parts into
typed values.
Details
Unlike
TemplateLiteral
, this schema decodes the matched string into a
readonly tuple with one element per schema part. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Parsing path parameters)
import { Schema } from "effect"
const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
// decodes "/user/42" => readonly ["/user/", 42]
Namespace for
TemplateLiteralParser
helper types.
Type-level representation returned by
TemplateLiteralParser
.
TemplateLiteralParser<function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts extends TemplateLiteral.type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Parts = readonly TemplateLiteral.Part[]Ordered list of parts used to construct a TemplateLiteral schema.
Parts> extends
interface BottomLazy<out Ast extends SchemaAST.AST, out Rebuild extends Top, in out TypeParameters extends ReadonlyArray<Constraint> = readonly [], 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">Lazy Bottom variant for schema implementations that compute their public
views on demand.
When to use
Use as an implementation base for schema interfaces that must expose
Bottom behavior without forcing TypeScript to eagerly evaluate expensive
Type, Encoded, or service views.
Details
The laziness is purely type-level; runtime behavior is unchanged.
BottomLazy keeps the structural operations inherited from Bottom, but
erases the expensive schema views to unknown. Concrete schema interfaces can
then redeclare the precise views they expose. This keeps wide schemas such as
Struct and Union cheaper when generic code reads a single view, while
preserving their exact public types.
BottomLazy<
import SchemaASTSchemaAST.class Arraysclass Arrays {
_tag: 'Arrays';
isMutable: boolean;
elements: ReadonlyArray<AST>;
rest: ReadonlyArray<AST>;
encodingChecks: Checks | undefined;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
_rebuild: (recur: (ast: AST) => AST, checks: Checks | undefined, encodingChecks: Checks | undefined) => Arrays;
recur: (recur: (ast: AST) => AST) => Arrays;
flip: (recur: (ast: AST) => AST) => Arrays;
getExpected: () => string;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node for array-like types — both tuples and arrays.
When to use
Use when constructing or inspecting AST nodes for tuple or array-like schemas,
including rest elements.
Details
elements — positional element types (tuple elements). An element is
optional if its
Context.isOptional
is true.
rest — the rest/variadic element types. When non-empty, the first
entry is the "spread" type (e.g. ...Array<string>), and subsequent
entries are trailing positional elements after the spread.
isMutable — whether the resulting array is readonly (false) or
mutable (true).
Gotchas
Construction enforces TypeScript ordering rules: a required element
cannot follow an optional one, and an optional element cannot follow a
rest element.
Example (Inspecting a tuple AST)
import { Schema, SchemaAST } from "effect"
const schema = Schema.Tuple([Schema.String, Schema.Number])
const ast = schema.ast
if (SchemaAST.isArrays(ast)) {
console.log(ast.elements.length) // 2
console.log(ast.rest.length) // 0
}
Arrays,
interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Schema for parsing matched template literal strings into typed tuple parts.
When to use
Use to validate a template literal string and decode the matched parts into
typed values.
Details
Unlike
TemplateLiteral
, this schema decodes the matched string into a
readonly tuple with one element per schema part. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Parsing path parameters)
import { Schema } from "effect"
const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
// decodes "/user/42" => readonly ["/user/", 42]
Namespace for
TemplateLiteralParser
helper types.
Type-level representation returned by
TemplateLiteralParser
.
TemplateLiteralParser<function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts>
>
{
readonly "Type": TemplateLiteralParser.type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts> = Parts extends readonly [infer Head, ...infer Tail] ? readonly [Head extends TemplateLiteral.LiteralPart ? Head : Head extends ConstraintDecoder<infer T, unknown> ? T : never, ...TemplateLiteralParser.Type<Tail>] : []Computes the decoded tuple type produced by TemplateLiteralParser.
Details
Literal parts contribute their literal value to the tuple. Schema parts
contribute their decoded Type.
Type<function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts>
readonly "Encoded": TemplateLiteral.type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Encoded<Parts> = Parts extends readonly [...infer Init, infer Last] ? TemplateLiteral.AppendType<TemplateLiteral.Encoded<Init>, Last> : ""Computes the encoded string literal type produced by concatenating the encoded
forms of all template literal parts.
Encoded<function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts>
readonly "DecodingServices": never
readonly "EncodingServices": never
readonly "~type.make.in": TemplateLiteralParser.type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts> = Parts extends readonly [infer Head, ...infer Tail] ? readonly [Head extends TemplateLiteral.LiteralPart ? Head : Head extends ConstraintDecoder<infer T, unknown> ? T : never, ...TemplateLiteralParser.Type<Tail>] : []Computes the decoded tuple type produced by TemplateLiteralParser.
Details
Literal parts contribute their literal value to the tuple. Schema parts
contribute their decoded Type.
Type<function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts>
readonly "~type.make": TemplateLiteralParser.type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts> = Parts extends readonly [infer Head, ...infer Tail] ? readonly [Head extends TemplateLiteral.LiteralPart ? Head : Head extends ConstraintDecoder<infer T, unknown> ? T : never, ...TemplateLiteralParser.Type<Tail>] : []Computes the decoded tuple type produced by TemplateLiteralParser.
Details
Literal parts contribute their literal value to the tuple. Schema parts
contribute their decoded Type.
Type<function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts>
readonly "Iso": TemplateLiteralParser.type TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.Type<Parts> = Parts extends readonly [infer Head, ...infer Tail] ? readonly [Head extends TemplateLiteral.LiteralPart ? Head : Head extends ConstraintDecoder<infer T, unknown> ? T : never, ...TemplateLiteralParser.Type<Tail>] : []Computes the decoded tuple type produced by TemplateLiteralParser.
Details
Literal parts contribute their literal value to the tuple. Schema parts
contribute their decoded Type.
Type<function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts>
readonly TemplateLiteralParser<Parts extends TemplateLiteral.Parts>.parts: Parts extends TemplateLiteral.Partsparts: function (type parameter) Parts in TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Parts
}
/**
* Schema for parsing matched template literal strings into typed tuple parts.
*
* **When to use**
*
* Use to validate a template literal string and decode the matched parts into
* typed values.
*
* **Details**
*
* Unlike {@link TemplateLiteral}, this schema decodes the matched string into a
* readonly tuple with one element per schema part. Checks on string, number,
* and bigint schema parts are applied while matching each segment.
*
* **Example** (Parsing path parameters)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
* // decodes "/user/42" => readonly ["/user/", 42]
* ```
*
* @see {@link TemplateLiteral} for a validation-only version that keeps the string encoded.
* @category constructors
* @since 3.10.0
*/
export function function TemplateLiteralParser<
Parts extends TemplateLiteral.Parts
>(parts: Parts): TemplateLiteralParser<Parts>
Schema for parsing matched template literal strings into typed tuple parts.
When to use
Use to validate a template literal string and decode the matched parts into
typed values.
Details
Unlike
TemplateLiteral
, this schema decodes the matched string into a
readonly tuple with one element per schema part. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Parsing path parameters)
import { Schema } from "effect"
const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
// decodes "/user/42" => readonly ["/user/", 42]
TemplateLiteralParser<const function (type parameter) Parts in TemplateLiteralParser<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteralParser<Parts>Parts extends TemplateLiteral.type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Parts = readonly TemplateLiteral.Part[]Ordered list of parts used to construct a TemplateLiteral schema.
Parts>(
parts: const Parts extends TemplateLiteral.Partsparts: function (type parameter) Parts in TemplateLiteralParser<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteralParser<Parts>Parts
): interface TemplateLiteralParser<Parts extends TemplateLiteral.Parts>Schema for parsing matched template literal strings into typed tuple parts.
When to use
Use to validate a template literal string and decode the matched parts into
typed values.
Details
Unlike
TemplateLiteral
, this schema decodes the matched string into a
readonly tuple with one element per schema part. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Parsing path parameters)
import { Schema } from "effect"
const schema = Schema.TemplateLiteralParser(["/user/", Schema.NumberFromString])
// decodes "/user/42" => readonly ["/user/", 42]
Namespace for
TemplateLiteralParser
helper types.
Type-level representation returned by
TemplateLiteralParser
.
TemplateLiteralParser<function (type parameter) Parts in TemplateLiteralParser<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteralParser<Parts>Parts> {
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(function templateLiteralFromParts<Parts>(
parts: Parts
): SchemaAST.TemplateLiteral
templateLiteralFromParts(parts: const Parts extends TemplateLiteral.Partsparts).TemplateLiteral.asTemplateLiteralParser(): ArraysasTemplateLiteralParser(), { parts: const Parts extends TemplateLiteral.Partsparts })
}