Skip to content

Function: createNullRecord()

API / @xmachines/core / utils / createNullRecord

function createNullRecord<V>(): Record<string, V>;

Defined in: packages/core/src/utils/null-record.ts:21

Builds an empty record with no prototype.

A record that collects keys from outside the program — the params of a URL, the query of a location — takes any key that the outside sends. An ordinary {} inherits from Object.prototype, so a key such as __proto__ writes the prototype and not an entry, and a key such as constructor reads a function that nobody stored. A record with no prototype holds each key as an own entry, and it reads nothing it did not store.

Type Parameters

Type Parameter
V

Returns

Record<string, V>

A new, empty record. Each call builds one.

Example

import { createNullRecord } from "@xmachines/core/utils";
const params = createNullRecord<string>();
params["__proto__"] = "x"; // an own entry, and the prototype stays null