Skip to main content
Module

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

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

An alternative to Set#has() that properly acts as a type guard.

It was rejected from being done in TypeScript itself.

Examples

Example 1

import {setHas} from 'ts-extras';

const values = ['a', 'b', 'c'] as const;
const valueSet = new Set(values);
const valueToCheck: unknown = 'a';

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

Type Parameters

Type extends SuperType
optional
SuperType = unknown

Parameters

set: ReadonlySet<Type>
item: SuperType

Returns

item is Type