(u: unknown): u is Context<never>Checks whether the provided argument is a Context.
When to use
Use to narrow an unknown value before passing it to APIs that require a
Context.
Details
This checks the runtime Context marker and does not inspect which services
the context contains.
Gotchas
This guard only proves that the value is a Context; it does not prove that
any specific service is present.
Example (Checking for contexts)
import { Context } from "effect"
import * as assert from "node:assert"
assert.strictEqual(Context.isContext(Context.empty()), true)export const const isContext: (
u: unknown
) => u is Context<never>
Checks whether the provided argument is a Context.
When to use
Use to narrow an unknown value before passing it to APIs that require a
Context.
Details
This checks the runtime Context marker and does not inspect which services
the context contains.
Gotchas
This guard only proves that the value is a Context; it does not prove that
any specific service is present.
Example (Checking for contexts)
import { Context } from "effect"
import * as assert from "node:assert"
assert.strictEqual(Context.isContext(Context.empty()), true)
isContext = (u: unknownu: unknown): u: unknownu is interface Context<in Services>Immutable collection of service implementations used for dependency
injection in Effect programs.
Details
The type parameter tracks the service identifiers available in the context.
At runtime, services are stored by each key's string key.
Example (Creating a context with multiple services)
import { Context } from "effect"
// Create a context with multiple services
const Logger = Context.Service<{ log: (msg: string) => void }>("Logger")
const Database = Context.Service<{ query: (sql: string) => string }>(
"Database"
)
const context = Context.make(Logger, {
log: (msg: string) => console.log(msg)
})
.pipe(Context.add(Database, { query: (sql) => `Result: ${sql}` }))
Context<never> => hasProperty<"~effect/Context">(self: unknown, property: "~effect/Context"): self is { [K in "~effect/Context"]: 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/Context"TypeId)