Hyperlinkv0.8.0-beta.28

Predicate

Predicate.isReadonlyObjectfunctioneffect/Predicate.ts:1066
(input: unknown): input is { readonly [x: PropertyKey]: unknown }

Checks whether a value is a non-null, non-array object and narrows it to a readonly indexable object type.

When to use

Use to narrow unknown input to a readonly view of a non-null, non-array object with a Predicate guard.

Details

Readonly-ness is a TypeScript type-level view; it is not observable at runtime. This delegates to isObject, so class instances and built-in object instances are accepted.

Example (Checking readonly objects)

import { Predicate } from "effect"

const data: unknown = { a: 1 }

console.log(Predicate.isReadonlyObject(data))
guardsisObject
export function isReadonlyObject(input: unknown): input is { readonly [x: PropertyKey]: unknown } {
  return isObject(input)
}