Template.ts
Template.ts overview
Section titled “Template.ts overview”Builds HTTP response text from template literals.
Template interpolations can be plain values, optional values, effects, or streams. The resulting effect or stream keeps the errors and service requirements from any effectful interpolations, which lets response helpers assemble dynamic text without losing type information.
Since v4.0.0
Exports Grouped by Category
Section titled “Exports Grouped by Category”constructors
Section titled “constructors”Creates an effectful string from a template literal.
Details
Primitive and Option interpolations are rendered immediately. Effect
interpolations are evaluated and rendered before the final string is produced.
Signature
declare const make: <A extends ReadonlyArray<Interpolated>>( strings: TemplateStringsArray, ...args: A) => Effect.Effect<string, Interpolated.Error<A[number]>, Interpolated.Context<A[number]>>Since v4.0.0
stream
Section titled “stream”Creates a stream of strings from a template literal.
Details
Static text is emitted with interpolated values. Effect interpolations are evaluated as stream chunks, and stream interpolations are flattened into the output.
Signature
declare const stream: <A extends ReadonlyArray<InterpolatedWithStream>>( strings: TemplateStringsArray, ...args: A) => Stream.Stream<string, Interpolated.Error<A[number]>, Interpolated.Context<A[number]>>Since v4.0.0
models
Section titled “models”Interpolated (type alias)
Section titled “Interpolated (type alias)”Value accepted by the string template constructor.
Details
Interpolations can be primitive values, optional primitive values, or effects that produce primitive values.
Signature
type Interpolated = Primitive | Option.Option<Primitive> | Effect.Effect<Primitive, any, any>Since v4.0.0
InterpolatedWithStream (type alias)
Section titled “InterpolatedWithStream (type alias)”Value accepted by the streaming template constructor.
Details
In addition to normal interpolations, stream interpolations can emit primitive values over time.
Signature
type InterpolatedWithStream = Interpolated | Stream.Stream<Primitive, any, any>Since v4.0.0
Primitive (type alias)
Section titled “Primitive (type alias)”Primitive template interpolation value.
Details
Arrays are rendered by converting each element to a string and concatenating the results.
Signature
type Primitive = PrimitiveValue | ReadonlyArray<PrimitiveValue>Since v4.0.0
PrimitiveValue (type alias)
Section titled “PrimitiveValue (type alias)”Primitive value that can be interpolated into an HTTP template.
Signature
type PrimitiveValue = string | number | bigint | boolean | null | undefinedSince v4.0.0
Interpolated (namespace)
Section titled “Interpolated (namespace)”Namespace containing type-level helpers for template interpolations.
Since v4.0.0
Context (type alias)
Section titled “Context (type alias)”Extracts the required context from an effect or stream interpolation.
Details
Plain values and Option interpolations contribute no context.
Signature
type Context<A> = A extends infer T ? T extends Option.Option<infer _> ? never : T extends Effect.Effect<infer _A, infer _E, infer R> ? R : T extends Stream.Stream<infer _A, infer _E, infer R> ? R : never : neverSince v4.0.0
Error (type alias)
Section titled “Error (type alias)”Extracts the error type from an effect or stream interpolation.
Details
Plain values and Option interpolations contribute no error type.
Signature
type Error<A> = A extends infer T ? T extends Option.Option<infer _> ? never : T extends Stream.Stream<infer _A, infer E, infer _R> ? E : T extends Effect.Effect<infer _A, infer E, infer _R> ? E : never : neverSince v4.0.0