(u: unknown): u is Key<any, any>Checks whether the provided argument is a Key.
Example (Checking for keys)
import { Context } from "effect"
import * as assert from "node:assert"
assert.strictEqual(Context.isKey(Context.Service("Service")), true)export const const isKey: (
u: unknown
) => u is Key<any, any>
Checks whether the provided argument is a Key.
Example (Checking for keys)
import { Context } from "effect"
import * as assert from "node:assert"
assert.strictEqual(Context.isKey(Context.Service("Service")), true)
isKey = (u: unknownu: unknown): u: unknownu is interface Key<out Identifier, out Shape>Typed identifier for a service stored in a Context.
When to use
Use as the typed handle for storing, retrieving, and requiring a specific
service in a Context.
Details
Identifier tracks the requirement in Effect types, while Shape is the
service implementation retrieved by the key. A key is also an Effect value,
so yielding it inside Effect.gen retrieves the service from the current
fiber context.
Key<any, any> => hasProperty<"~effect/Context/Service">(self: unknown, property: "~effect/Context/Service"): self is { [K in "~effect/Context/Service"]: 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 ServiceTypeId: ServiceTypeIdString literal type used as the runtime type identifier for Context
service keys.
Runtime type identifier attached to Context service keys and used by
isKey to recognize them.
ServiceTypeId)