API reference@evolu/commonObject › getOwnProp

function getOwnProp<K, V>(
  record: ReadonlyRecord<K, V>,
  key: NoInfer,
): V | undefined;

Defined in: packages/common/src/Object.ts:403

Gets an own property from a record, returning undefined if the key is missing or inherited.

TypeScript's Record<K, V> type assumes all keys exist, but at runtime accessing a missing key returns undefined. This helper provides proper typing for that case without treating properties inherited from Object.prototype as record data.

Example

import { assertEqual, assertType, getOwnProp } from "@evolu/common";

interface User {
  readonly name: string;
}

const users: Readonly<Record<string, User>> = {
  alice: { name: "Alice" },
};
const user = getOwnProp(users, "bob");

assertType<User | undefined, typeof user>();
assertEqual(user, undefined);
assertEqual(getOwnProp(users, "toString"), undefined);