<R extends Request<any, any, any> & { _tag: string }>(
tag: R["_tag"]
): Constructor<R, "_tag">Creates a constructor function for a tagged Request type. The tag is automatically added to the request, making it useful for discriminated unions.
Example (Creating tagged request constructors)
import { Request } from "effect"
declare const User: unique symbol
declare const UserNotFound: unique symbol
declare const Post: unique symbol
declare const PostNotFound: unique symbol
type User = typeof User
type UserNotFound = typeof UserNotFound
type Post = typeof Post
type PostNotFound = typeof PostNotFound
interface GetUser extends Request.Request<User, UserNotFound> {
readonly _tag: "GetUser"
readonly id: string
}
interface GetPost extends Request.Request<Post, PostNotFound> {
readonly _tag: "GetPost"
readonly id: string
}
const GetUser = Request.tagged<GetUser>("GetUser")
const GetPost = Request.tagged<GetPost>("GetPost")
const userRequest = GetUser({ id: "user-123" })
const postRequest = GetPost({ id: "post-456" })
// _tag is automatically set
console.log(userRequest._tag) // "GetUser"
console.log(postRequest._tag) // "GetPost"export const const tagged: <
R extends Request<any, any, any> & {
_tag: string
}
>(
tag: R["_tag"]
) => Constructor<R, "_tag">
Creates a constructor function for a tagged Request type. The tag is automatically
added to the request, making it useful for discriminated unions.
Example (Creating tagged request constructors)
import { Request } from "effect"
declare const User: unique symbol
declare const UserNotFound: unique symbol
declare const Post: unique symbol
declare const PostNotFound: unique symbol
type User = typeof User
type UserNotFound = typeof UserNotFound
type Post = typeof Post
type PostNotFound = typeof PostNotFound
interface GetUser extends Request.Request<User, UserNotFound> {
readonly _tag: "GetUser"
readonly id: string
}
interface GetPost extends Request.Request<Post, PostNotFound> {
readonly _tag: "GetPost"
readonly id: string
}
const GetUser = Request.tagged<GetUser>("GetUser")
const GetPost = Request.tagged<GetPost>("GetPost")
const userRequest = GetUser({ id: "user-123" })
const postRequest = GetPost({ id: "post-456" })
// _tag is automatically set
console.log(userRequest._tag) // "GetUser"
console.log(postRequest._tag) // "GetPost"
tagged = <function (type parameter) R in <R extends Request<any, any, any> & {
_tag: string;
}>(tag: R["_tag"]): Constructor<R, "_tag">
R extends interface Request<out A, out E = never, out R = never>A Request<A, E, R> is a request from a data source for a value of type A
that may fail with an E and have requirements of type R.
Example (Defining typed requests)
import type { Request } from "effect"
// Define a request that fetches a user by ID
interface GetUser extends Request.Request<string, Error> {
readonly _tag: "GetUser"
readonly id: number
}
// Define a request that fetches all users
interface GetAllUsers extends Request.Request<ReadonlyArray<string>, Error> {
readonly _tag: "GetAllUsers"
}
Request<any, any, any> & { _tag: string_tag: string }>(
tag: R["_tag"]tag: function (type parameter) R in <R extends Request<any, any, any> & {
_tag: string;
}>(tag: R["_tag"]): Constructor<R, "_tag">
R["_tag"]
): interface Constructor<R extends Request<any, any, any>, T extends keyof R = never>The constructor type returned by Request.of and Request.tagged.
Details
The constructor accepts the request's data fields, excluding request variance
fields and any fields already supplied by the constructor such as _tag, and
returns a value of the request type.
Example (Using generated request constructors)
import { Request } from "effect"
interface GetUser extends Request.Request<string, Error> {
readonly _tag: "GetUser"
readonly id: number
}
// Constructor type is used internally by Request.of() and Request.tagged()
const GetUser = Request.tagged<GetUser>("GetUser")
const userRequest = GetUser({ id: 123 })
Constructor<function (type parameter) R in <R extends Request<any, any, any> & {
_tag: string;
}>(tag: R["_tag"]): Constructor<R, "_tag">
R, "_tag"> =>
(args: Types.VoidIfEmpty<
Types.Simplify<
Omit<R, "_tag" | "~effect/Request">
>
>
args) => {
const const request: anyrequest = var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.create(o: object | null): any (+1 overload)Creates an object that has the specified prototype or that has null prototype.
create(const RequestPrototype: Request<
any,
any,
any
>
Prototype used by Effect's request constructors.
Details
This low-level value provides the structural request marker for values
created by Request.of, Request.tagged, Request.Class, and
Request.TaggedClass. Most users should use those constructors instead of
interacting with the prototype directly.
RequestPrototype)
if (args: Types.VoidIfEmpty<
Types.Simplify<
Omit<R, "_tag" | "~effect/Request">
>
>
args) var Object: ObjectConstructorProvides functionality common to all JavaScript objects.
Object.ObjectConstructor.assign<any, NonNullable<Types.VoidIfEmpty<Types.Simplify<Omit<R, "~effect/Request" | "_tag">>>>>(target: any, source: NonNullable<Types.VoidIfEmpty<Types.Simplify<Omit<R, "~effect/Request" | "_tag">>>>): any (+3 overloads)Copy the values of all of the enumerable own properties from one or more source objects to a
target object. Returns the target object.
assign(const request: anyrequest, args: NonNullable<
Types.VoidIfEmpty<
Types.Simplify<
Omit<R, "_tag" | "~effect/Request">
>
>
>
args)
const request: anyrequest._tag = tag: R["_tag"]tag
return const request: anyrequest
}