Skip to content

isSet

Checks if a value is a Set instance.

Available since v3.0.0

import { isSet } from '@helpers4/guard';
// or, from the all-in-one package (same code, one install):
import { isSet } from 'helpers4/guard';
isSet(value: unknown): value is Set<unknown>
ParameterTypeDescription
valueunknownThe value to check

value is Set<unknown> — True if value is a Set

Returns true only for real Set instances.

isSet(new Set([1, 2, 3])) // => true
isSet([1, 2, 3])          // => false

Inside the if branch, the value is narrowed to Set.

const value: unknown = new Set(['a', 'b']);
if (isSet(value)) {
  value.size // => 2, type-safe access
}

View source on GitHub