(u: unknown): u is TxSubscriptionRef<unknown>Checks whether the given value is a TxSubscriptionRef.
When to use
Use to narrow an unknown value before treating it as a TxSubscriptionRef.
Example (Checking transactional subscription references)
import { TxSubscriptionRef } from "effect"
declare const someValue: unknown
if (TxSubscriptionRef.isTxSubscriptionRef(someValue)) {
console.log("This is a TxSubscriptionRef")
}export const const isTxSubscriptionRef: (
u: unknown
) => u is TxSubscriptionRef<unknown>
Checks whether the given value is a TxSubscriptionRef.
When to use
Use to narrow an unknown value before treating it as a TxSubscriptionRef.
Example (Checking transactional subscription references)
import { TxSubscriptionRef } from "effect"
declare const someValue: unknown
if (TxSubscriptionRef.isTxSubscriptionRef(someValue)) {
console.log("This is a TxSubscriptionRef")
}
isTxSubscriptionRef = (u: unknownu: unknown): u: unknownu is interface TxSubscriptionRef<in out A>A TxSubscriptionRef is a transactional reference that allows subscribing to all
committed changes. Subscribers receive the current value followed by every subsequent
update via a transactional dequeue.
When to use
Use to store transactional state whose committed changes must be observable by
subscribers.
Example (Subscribing to transactional changes)
import { Effect, TxQueue, TxSubscriptionRef } from "effect"
const program = Effect.gen(function*() {
const ref = yield* TxSubscriptionRef.make(0)
yield* Effect.scoped(
Effect.gen(function*() {
const sub = yield* TxSubscriptionRef.changes(ref)
const initial = yield* TxQueue.take(sub)
console.log(initial) // 0
yield* TxSubscriptionRef.set(ref, 1)
const next = yield* TxQueue.take(sub)
console.log(next) // 1
})
)
})
TxSubscriptionRef<unknown> => hasProperty<"~effect/transactions/TxSubscriptionRef">(self: unknown, property: "~effect/transactions/TxSubscriptionRef"): self is { [K in "~effect/transactions/TxSubscriptionRef"]: 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/transactions/TxSubscriptionRef"TypeId)