<P extends PropertyKey>(property: P): (
self: unknown
) => self is { [K in P]: unknown }
<P extends PropertyKey>(self: unknown, property: P): self is {
[K in P]: unknown
}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)
}export const const hasProperty: {
<P extends PropertyKey>(property: P): (
self: unknown
) => self is { [K in P]: unknown }
<P extends PropertyKey>(
self: unknown,
property: P
): self is { [K in P]: unknown }
}
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: {
<function (type parameter) P in <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown; }P extends type PropertyKey =
| string
| number
| symbol
PropertyKey>(property: P extends PropertyKeyproperty: function (type parameter) P in <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown; }P): (self: unknownself: unknown) => self: unknownself is { [function (type parameter) KK in function (type parameter) P in <P extends PropertyKey>(property: P): (self: unknown) => self is { [K in P]: unknown; }P]: unknown }
<function (type parameter) P in <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown; }P extends type PropertyKey =
| string
| number
| symbol
PropertyKey>(self: unknownself: unknown, property: P extends PropertyKeyproperty: function (type parameter) P in <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown; }P): self: unknownself is { [function (type parameter) KK in function (type parameter) P in <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown; }P]: unknown }
} = import dualdual(
2,
<function (type parameter) P in <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown; }P extends type PropertyKey =
| string
| number
| symbol
PropertyKey>(self: unknownself: unknown, property: P extends PropertyKeyproperty: function (type parameter) P in <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown; }P): self: unknownself is { [function (type parameter) KK in function (type parameter) P in <P extends PropertyKey>(self: unknown, property: P): self is { [K in P]: unknown; }P]: unknown } =>
function isObjectKeyword(
input: unknown
): input is object
Checks whether a value is an object in the JavaScript sense (objects, arrays, functions).
When to use
Use when you need a Predicate guard that accepts arrays and functions as
well as objects.
Details
Returns true for arrays and functions, and false for null.
Example (Checking object keywords)
import { Predicate } from "effect"
console.log(Predicate.isObjectKeyword(() => 1))
console.log(Predicate.isObjectKeyword(null))
isObjectKeyword(self: unknownself) && (property: P extends PropertyKeyproperty in self: objectself)
)