Skip to main content
Module

x/unknownutil/is.ts>isRecord

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function isRecord
import { isRecord } from "https://deno.land/x/unknownutil@v3.18.0/is.ts";

Return true if the type of x satisfies Record<PropertyKey, unknown>.

Note that this function returns true for ambiguous instances like Set, Map, Date, Promise, etc.

import { is } from "@core/unknownutil";

const a: unknown = {"a": 0, "b": 1};
if (is.Record(a)) {
  // a is narrowed to Record<PropertyKey, unknown>
  const _: Record<PropertyKey, unknown> = a;
}

const b: unknown = new Set();
if (is.Record(b)) {
  // b is narrowed to Record<PropertyKey, unknown>
  const _: Record<PropertyKey, unknown> = b;
}

Parameters

x: unknown

Returns

x is Record<PropertyKey, unknown>