TemplateLiteral<Parts>Creates a schema that validates strings by matching ordered template literal parts.
When to use
Use when the decoded value should remain the matched string and you do not need the individual template parts parsed into a tuple.
Details
Each part can be a literal string, number, or bigint, or a schema whose
encoded type is string, number, or bigint. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Defining a URL path pattern)
import { Schema } from "effect"
const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
// matches strings like "/user/123", "/user/42", etc.export declare namespace TemplateLiteral {
/**
* Constraint for schema parts that can appear inside a `TemplateLiteral`.
*
* **Details**
*
* The schema's encoded value must be a `string`, `number`, or `bigint` so it can
* be converted into a template literal string segment.
*
* @category utility types
* @since 4.0.0
*/
export interface interface TemplateLiteral<Parts extends TemplateLiteral.Parts>.SchemaPartConstraint for schema parts that can appear inside a TemplateLiteral.
Details
The schema's encoded value must be a string, number, or bigint so it can
be converted into a template literal string segment.
SchemaPart extends Constraint {
readonly TemplateLiteral<Parts extends TemplateLiteral.Parts>.SchemaPart.Encoded: string | number | bigintEncoded: string | number | bigint
}
/**
* Literal value that can be used directly as a part of a `TemplateLiteral`.
*
* @category utility types
* @since 4.0.0
*/
export type type TemplateLiteral<Parts extends TemplateLiteral.Parts>.LiteralPart = string | number | bigintLiteral value that can be used directly as a part of a TemplateLiteral.
LiteralPart = string | number | bigint
/**
* A single part of a `TemplateLiteral`, either an interpolated schema part or a
* literal `string`, `number`, or `bigint`.
*
* @category utility types
* @since 4.0.0
*/
export type type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Part = SchemaPart | LiteralPartA single part of a TemplateLiteral, either an interpolated schema part or a
literal string, number, or bigint.
Part = interface TemplateLiteral<Parts extends TemplateLiteral.Parts>.SchemaPartConstraint for schema parts that can appear inside a TemplateLiteral.
Details
The schema's encoded value must be a string, number, or bigint so it can
be converted into a template literal string segment.
SchemaPart | type TemplateLiteral<Parts extends TemplateLiteral.Parts>.LiteralPart = string | number | bigintLiteral value that can be used directly as a part of a TemplateLiteral.
LiteralPart
/**
* Ordered list of parts used to construct a `TemplateLiteral` schema.
*
* @category utility types
* @since 4.0.0
*/
export type type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Parts = readonly Part[]Ordered list of parts used to construct a TemplateLiteral schema.
Parts = interface ReadonlyArray<T>ReadonlyArray<type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Part = SchemaPart | LiteralPartA single part of a TemplateLiteral, either an interpolated schema part or a
literal string, number, or bigint.
Part>
type type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next> = Next extends LiteralPart ? `${Template}${Next}` : Next extends {
readonly Encoded: infer E extends LiteralPart;
} ? `${Template}${E}` : never
AppendType<
function (type parameter) Template in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next>Template extends string,
function (type parameter) Next in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next>Next
> = function (type parameter) Next in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next>Next extends 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) Template in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next>Template}${function (type parameter) Next in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next>Next}`
: function (type parameter) Next in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next>Next extends { readonly type Encoded: E extends LiteralPartEncoded: infer function (type parameter) EE extends 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) Template in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next>Template}${function (type parameter) EE}`
: never
/**
* Computes the encoded string literal type produced by concatenating the encoded
* forms of all template literal parts.
*
* @category utility types
* @since 3.10.0
*/
export type type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Encoded<Parts> = Parts extends readonly [...infer Init, infer Last] ? AppendType<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 type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Encoded<Parts>Parts> = function (type parameter) Parts in type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Encoded<Parts>Parts extends readonly [...infer function (type parameter) InitInit, infer function (type parameter) LastLast] ? type TemplateLiteral<Parts extends TemplateLiteral.Parts>.AppendType<Template extends string, Next> = Next extends LiteralPart ? `${Template}${Next}` : Next extends {
readonly Encoded: infer E extends LiteralPart;
} ? `${Template}${E}` : never
AppendType<type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Encoded<Parts> = Parts extends readonly [...infer Init, infer Last] ? AppendType<Encoded<Init>, Last> : ""Computes the encoded string literal type produced by concatenating the encoded
forms of all template literal parts.
Encoded<function (type parameter) InitInit>, function (type parameter) LastLast>
: ``
}
/**
* Type-level representation returned by {@link TemplateLiteral}.
*
* @category models
* @since 3.10.0
*/
export interface interface TemplateLiteral<Parts extends TemplateLiteral.Parts>Creates a schema that validates strings by matching ordered template literal
parts.
When to use
Use when the decoded value should remain the matched string and you do not
need the individual template parts parsed into a tuple.
Details
Each part can be a literal string, number, or bigint, or a schema whose
encoded type is string, number, or bigint. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Defining a URL path pattern)
import { Schema } from "effect"
const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
// matches strings like "/user/123", "/user/42", etc.
Namespace for
TemplateLiteral
helper types.
Type-level representation returned by
TemplateLiteral
.
TemplateLiteral<function (type parameter) Parts in TemplateLiteral<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 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<
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 TemplateLiteral<Parts extends TemplateLiteral.Parts>Parts>,
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 TemplateLiteral<Parts extends TemplateLiteral.Parts>Parts>,
never,
never,
import SchemaASTSchemaAST.class TemplateLiteralclass TemplateLiteral {
_tag: 'TemplateLiteral';
parts: ReadonlyArray<AST>;
encodedParts: ReadonlyArray<TemplateLiteralPart>;
getParser: (recur: (ast: AST) => SchemaParser.Parser) => SchemaParser.Parser;
getExpected: () => string;
matchPart: (s: string, options: ParseOptions) => string | undefined;
asTemplateLiteralParser: () => Arrays;
annotations: Schema.Annotations.Annotations | undefined;
checks: Checks | undefined;
encoding: Encoding | undefined;
context: Context | undefined;
toString: () => string;
}
AST node representing a TypeScript template literal type
(e.g. `user_${string}`).
Details
parts is an array of AST nodes; each part contributes to matching
strings at runtime.
TemplateLiteral,
interface TemplateLiteral<Parts extends TemplateLiteral.Parts>Creates a schema that validates strings by matching ordered template literal
parts.
When to use
Use when the decoded value should remain the matched string and you do not
need the individual template parts parsed into a tuple.
Details
Each part can be a literal string, number, or bigint, or a schema whose
encoded type is string, number, or bigint. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Defining a URL path pattern)
import { Schema } from "effect"
const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
// matches strings like "/user/123", "/user/42", etc.
Namespace for
TemplateLiteral
helper types.
Type-level representation returned by
TemplateLiteral
.
TemplateLiteral<function (type parameter) Parts in TemplateLiteral<Parts extends TemplateLiteral.Parts>Parts>
>
{
readonly TemplateLiteral<Parts extends TemplateLiteral.Parts>.parts: Parts extends TemplateLiteral.Partsparts: function (type parameter) Parts in TemplateLiteral<Parts extends TemplateLiteral.Parts>Parts
}
function function templateLiteralFromParts<
Parts extends TemplateLiteral.Parts
>(parts: Parts): SchemaAST.TemplateLiteral
templateLiteralFromParts<function (type parameter) Parts in templateLiteralFromParts<Parts extends TemplateLiteral.Parts>(parts: Parts): SchemaAST.TemplateLiteralParts extends TemplateLiteral.type TemplateLiteral<Parts extends TemplateLiteral.Parts>.Parts = readonly TemplateLiteral.Part[]Ordered list of parts used to construct a TemplateLiteral schema.
Parts>(parts: Parts extends TemplateLiteral.Partsparts: function (type parameter) Parts in templateLiteralFromParts<Parts extends TemplateLiteral.Parts>(parts: Parts): SchemaAST.TemplateLiteralParts) {
return new import SchemaASTSchemaAST.constructor TemplateLiteral(parts: ReadonlyArray<SchemaAST.AST>, annotations?: Annotations.Annotations, checks?: SchemaAST.Checks, encoding?: SchemaAST.Encoding, context?: SchemaAST.Context): SchemaAST.TemplateLiteralAST node representing a TypeScript template literal type
(e.g. `user_${string}`).
Details
parts is an array of AST nodes; each part contributes to matching
strings at runtime.
TemplateLiteral(
parts: Parts extends TemplateLiteral.Partsparts.ReadonlyArray<TemplateLiteral<Parts extends TemplateLiteral.Parts>.Part>.map<SchemaAST.AST>(callbackfn: (value: TemplateLiteral<Parts extends TemplateLiteral.Parts>.Part, index: number, array: readonly TemplateLiteral.Part[]) => SchemaAST.AST, thisArg?: any): SchemaAST.AST[]Calls a defined callback function on each element of an array, and returns an array that contains the results.
map((part: TemplateLiteral.Partpart) => function isSchema(u: unknown): u is TopChecks whether a value is a Schema.
isSchema(part: TemplateLiteral.Partpart) ? part: TemplateLiteral.Part & Toppart.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">["ast"]: SchemaAST.ASTast : new import SchemaASTSchemaAST.constructor Literal(literal: SchemaAST.LiteralValue, annotations?: Annotations.Annotations, checks?: SchemaAST.Checks, encoding?: SchemaAST.Encoding, context?: SchemaAST.Context): SchemaAST.LiteralAST node matching an exact primitive value (string, number, boolean, or
bigint).
Details
Parsing succeeds only when the input is strictly equal (===) to the
stored literal. Numeric literals must be finite — Infinity, -Infinity,
and NaN are rejected at construction time.
Example (Creating a literal AST)
import { SchemaAST } from "effect"
const ast = new SchemaAST.Literal("active")
console.log(ast.literal) // "active"
Literal(part: TemplateLiteral.Partpart as TemplateLiteral.type TemplateLiteral<Parts extends TemplateLiteral.Parts>.LiteralPart = string | number | bigintLiteral value that can be used directly as a part of a TemplateLiteral.
LiteralPart))
)
}
/**
* Creates a schema that validates strings by matching ordered template literal
* parts.
*
* **When to use**
*
* Use when the decoded value should remain the matched string and you do not
* need the individual template parts parsed into a tuple.
*
* **Details**
*
* Each part can be a literal `string`, `number`, or `bigint`, or a schema whose
* encoded type is `string`, `number`, or `bigint`. Checks on string, number,
* and bigint schema parts are applied while matching each segment.
*
* **Example** (Defining a URL path pattern)
*
* ```ts
* import { Schema } from "effect"
*
* const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
* // matches strings like "/user/123", "/user/42", etc.
* ```
*
* @see {@link TemplateLiteralParser} for a schema that also parses matched parts into a tuple.
* @category constructors
* @since 3.10.0
*/
export function function TemplateLiteral<
Parts extends TemplateLiteral.Parts
>(parts: Parts): TemplateLiteral<Parts>
Creates a schema that validates strings by matching ordered template literal
parts.
When to use
Use when the decoded value should remain the matched string and you do not
need the individual template parts parsed into a tuple.
Details
Each part can be a literal string, number, or bigint, or a schema whose
encoded type is string, number, or bigint. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Defining a URL path pattern)
import { Schema } from "effect"
const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
// matches strings like "/user/123", "/user/42", etc.
TemplateLiteral<const function (type parameter) Parts in TemplateLiteral<const Parts extends TemplateLiteral.Parts>(parts: Parts): 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>(parts: const Parts extends TemplateLiteral.Partsparts: function (type parameter) Parts in TemplateLiteral<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteral<Parts>Parts): interface TemplateLiteral<Parts extends TemplateLiteral.Parts>Creates a schema that validates strings by matching ordered template literal
parts.
When to use
Use when the decoded value should remain the matched string and you do not
need the individual template parts parsed into a tuple.
Details
Each part can be a literal string, number, or bigint, or a schema whose
encoded type is string, number, or bigint. Checks on string, number,
and bigint schema parts are applied while matching each segment.
Example (Defining a URL path pattern)
import { Schema } from "effect"
const schema = Schema.TemplateLiteral(["/user/", Schema.Number])
// matches strings like "/user/123", "/user/42", etc.
Namespace for
TemplateLiteral
helper types.
Type-level representation returned by
TemplateLiteral
.
TemplateLiteral<function (type parameter) Parts in TemplateLiteral<const Parts extends TemplateLiteral.Parts>(parts: Parts): TemplateLiteral<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), { parts: const Parts extends TemplateLiteral.Partsparts })
}