es-toolkit/docs/zh_hans/reference/predicate/isSet.md
hyesung oh 893ed163f3
Some checks failed
CI / codecov (push) Has been cancelled
Release / release (push) Has been cancelled
docs(predicate): append docs fot isSet and isMap (#604)
2024-09-27 10:28:23 +09:00

715 B

isSet

检查给定值是否为 Set

此函数测试提供的值是否为 Set 的实例。 如果值是 Set,则返回 true,否则返回 false

此函数还可以作为 TypeScript 中的类型谓词,将参数的类型缩小为 Set

签名

function isSet(value: unknown): value is Set<any>;

参数

  • value (unknown): 要检查的值。

返回值

(value is Set<any>): 如果值是 Set,则为 true;否则为 false

示例

const value1 = new Set();
const value2 = new Map();
const value3 = new WeakSet();

console.log(isSet(value1)); // true
console.log(isSet(value2)); // false
console.log(isSet(value3)); // false