Skip to main content
Module

x/silicon/deps.ts>isTupleOf

Deno module to generate images from source code using Aloxaf/silicon.
Latest
function isTupleOf
import { isTupleOf } from "https://deno.land/x/silicon@v1.0.0/deps.ts";

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

import is from "./is.ts";

const predTup = [is.Number, is.String, is.Boolean] as const;
const a: unknown = [0, "a", true];
if (is.TupleOf(predTup)(a)) {
 // a is narrowed to [number, string, boolean]
 const _: readonly [number, string, boolean] = a;
}

Note that predTup must be readonly (as const) to infer the type of a correctly. TypeScript won't argues if predTup is not readonly because of its design limitation. https://github.com/microsoft/TypeScript/issues/34274#issuecomment-541691353

Type Parameters

T extends readonly Predicate<unknown>[]

Parameters

predTup: T