Skip to main content
Module

x/scaffold/src/deps/npm.ts>arrayIncludes

scaffold your next project with style and 💗
Latest
function arrayIncludes
import { arrayIncludes } from "https://deno.land/x/scaffold@0.3.0/src/deps/npm.ts";

An alternative to Array#includes() that properly acts as a type guard.

It was rejected from being done in TypeScript itself.

Examples

Example 1

import {arrayIncludes} from 'ts-extras';

const values = ['a', 'b', 'c'] as const;
const valueToCheck: unknown = 'a';

if (arrayIncludes(values, valueToCheck)) {
    // We now know that the value is of type `typeof values[number]`.
}

Type Parameters

Type extends SuperType
optional
SuperType = unknown

Parameters

array: Type[] | readonly Type[]
item: SuperType
optional
fromIndex: number

Returns

item is Type