Skip to main content
Module

x/unknownutil/mod.ts>isUnwrapReadonlyOf

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

Return an Readonly un-annotated type predicate function that returns true if the type of x is T.

This is unstable and may be removed in the future.

To enhance performance, users are advised to cache the return value of this function and mitigate the creation cost.

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

const isMyType = is.UnwrapReadonlyOf(is.ReadonlyOf(is.TupleOf([is.String, is.Number])));
const a: unknown = ["a", 1];
if (isMyType(a)) {
  // a is narrowed to [string, number]
  const _: [string, number] = a;
}

Type Parameters

P extends Predicate<unknown>

Returns

UnwrapReadonlyOf<P>