(u: unknown): u is PropertyKeyChecks whether a value is a valid PropertyKey (string, number, or symbol).
When to use
Use when you need a Predicate guard for unknown property keys before
indexing.
Details
Uses isString, isNumber, and isSymbol.
Example (Guarding property keys)
import { Predicate } from "effect"
const key: unknown = "name"
const obj: Record<PropertyKey, unknown> = { name: "Ada" }
if (Predicate.isPropertyKey(key) && key in obj) {
console.log(obj[key])
}export function function isPropertyKey(
u: unknown
): u is PropertyKey
Checks whether a value is a valid PropertyKey (string, number, or symbol).
When to use
Use when you need a Predicate guard for unknown property keys before
indexing.
Details
Uses isString, isNumber, and isSymbol.
Example (Guarding property keys)
import { Predicate } from "effect"
const key: unknown = "name"
const obj: Record<PropertyKey, unknown> = { name: "Ada" }
if (Predicate.isPropertyKey(key) && key in obj) {
console.log(obj[key])
}
isPropertyKey(u: unknownu: unknown): u: unknownu is type PropertyKey =
| string
| number
| symbol
PropertyKey {
return function isString(
input: unknown
): input is string
Checks whether a value is a string.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
string.
Details
Uses typeof input === "string".
Example (Guarding strings)
import { Predicate } from "effect"
const data: unknown = "hi"
if (Predicate.isString(data)) {
console.log(data.toUpperCase())
}
isString(u: unknownu) || function isNumber(
input: unknown
): input is number
Checks whether a value is a number.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
number.
Details
Uses typeof input === "number" and does not exclude NaN or Infinity.
Example (Guarding numbers)
import { Predicate } from "effect"
const data: unknown = 42
if (Predicate.isNumber(data)) {
console.log(data + 1)
}
isNumber(u: unknownu) || function isSymbol(
input: unknown
): input is symbol
Checks whether a value is a symbol.
When to use
Use when you need a Predicate guard to narrow an unknown value to a
symbol.
Details
Uses typeof input === "symbol".
Example (Guarding symbols)
import { Predicate } from "effect"
const data: unknown = Symbol.for("id")
if (Predicate.isSymbol(data)) {
console.log(data.description)
}
isSymbol(u: unknownu)
}