import { isUniformTupleOf } from "https://deno.land/x/unknownutil@v3.18.0/mod.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;
}
Returns
Predicate<UniformTupleOf<T, N>> & WithMetadata<IsUniformTupleOfMetadata>