Skip to main content
Module

x/unknownutil/is.ts>isUniformTupleOf

🦕 A lightweight utility pack for handling unknown type
Go to Latest
function isUniformTupleOf
import { isUniformTupleOf } 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 UniformTupleOf<T>.

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

With predicate function:

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

const isMyType = is.UniformTupleOf(5, is.Number);
const a: unknown = [0, 1, 2, 3, 4];
if (isMyType(a)) {
  // a is narrowed to [number, number, number, number, number]
  const _: [number, number, number, number, number] = a;
}

Type Parameters

T
N extends number

Parameters

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

Returns

Predicate<UniformTupleOf<T, N>> & WithMetadata<IsUniformTupleOfMetadata>