(u: unknown): u is Request<unknown, unknown, unknown>Checks whether a value is a Request.
Example (Checking request values)
import { Request } from "effect"
declare const User: unique symbol
declare const UserNotFound: unique symbol
type User = typeof User
type UserNotFound = typeof UserNotFound
interface GetUser extends Request.Request<User, UserNotFound> {
readonly _tag: "GetUser"
readonly id: string
}
const GetUser = Request.tagged<GetUser>("GetUser")
const request = GetUser({ id: "123" })
console.log(Request.isRequest(request)) // true
console.log(Request.isRequest("not a request")) // falseguards
Source effect/Request.ts:2511 lines
export const const isRequest: (
u: unknown
) => u is Request<unknown, unknown, unknown>
Checks whether a value is a Request.
Example (Checking request values)
import { Request } from "effect"
declare const User: unique symbol
declare const UserNotFound: unique symbol
type User = typeof User
type UserNotFound = typeof UserNotFound
interface GetUser extends Request.Request<User, UserNotFound> {
readonly _tag: "GetUser"
readonly id: string
}
const GetUser = Request.tagged<GetUser>("GetUser")
const request = GetUser({ id: "123" })
console.log(Request.isRequest(request)) // true
console.log(Request.isRequest("not a request")) // false
isRequest = (u: unknownu: unknown): u: unknownu is 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<unknown, unknown, unknown> => hasProperty<"~effect/Request">(self: unknown, property: "~effect/Request"): self is { [K in "~effect/Request"]: unknown; } (+1 overload)Checks whether a value has a given property key.
When to use
Use when you need a Predicate guard for property access on unknown
values with a simple structural object check.
Details
Uses the in operator and isObjectKeyword. This does not check property
value types.
Example (Guarding object properties)
import { Predicate } from "effect"
const hasName = Predicate.hasProperty("name")
const data: unknown = { name: "Ada" }
if (hasName(data)) {
console.log(data.name)
}
hasProperty(u: unknownu, const TypeId: "~effect/Request"TypeId)