assertObjectMatches
Assert that an object matches a partial deep object structure, with type-narrowing.
Plain objects are matched partially and recursively.
Arrays are matched by length and by recursively matching each element in order.
Matcher values are evaluated with their matcher predicate.
Dates are compared by the instant they hold.
Primitive values and other objects are compared using Object.is.
import { assertObjectMatches, oneOf, typeString } from "@kensio/smartass"
const user: unknown = { name: "Ada", role: "admin",};
assertObjectMatches(user, { name: typeString(), role: oneOf(["admin", "editor"] as const),});
// user is now narrowed to an object with a string name// and a role of "admin" | "editor"Source
Section titled “Source”Source file: src/assert/object-matches/object-matches.assert.ts
