Skip to main content
Module

x/unknownutil/is.ts>isReadonlyUniformTupleOf

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function isReadonlyUniformTupleOf
Deprecated
Deprecated

Use is.ReadonlyOf(is.UniformTupleOf(...)) instead.

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.ReadonlyUniformTupleOf(5);
const a: unknown = [0, 1, 2, 3, 4];
if (isMyType(a)) {
// a is narrowed to readonly [unknown, unknown, unknown, unknown, unknown]
const _: readonly [unknown, unknown, unknown, unknown, unknown] = a;
}

With predicate function:

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

const isMyType = is.ReadonlyUniformTupleOf(5, is.Number);
const a: unknown = [0, 1, 2, 3, 4];
if (isMyType(a)) {
// a is narrowed to readonly [number, number, number, number, number]
const _: readonly [number, number, number, number, number] = a;
}
import { isReadonlyUniformTupleOf } from "https://deno.land/x/unknownutil@v3.18.0/is.ts";

Return a type predicate function that returns true if the type of x is Readonly<UniformTupleOf<T>>.

Type Parameters

T
N extends number

Parameters

n: N
optional
pred: Predicate<T> = [UNSUPPORTED]

Returns

Predicate<Readonly<UniformTupleOf<T, N>>> & WithMetadata<IsReadonlyOfMetadata>