-
-
Notifications
You must be signed in to change notification settings - Fork 0
set like
function isExtendedSetLike<T>(it: unknown): it is ExtendedSetLike<T>;Checks whether the provided value is a
ExtendedSetLike
object. The ExtendedSetLike interface is the full implementation of a
ExtendedSetLike object, including all the composition methods like union,
intersection, difference, and symmetricDifference.
The ExtendedSetLike type is the shape of the native Set object in JavaScript
after the introduction of the TC39 Proposal for Set Methods, which added the
composition methods to the API.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a
ExtendedSetLike
object; otherwise, false.
Guards
function isExtendedSetLikeConstructor(
it: unknown,
): it is ExtendedSetLikeConstructor;Checks if a given value appears to be a
ExtendedSetLikeConstructor
function, including a prototype property that appears to be a
ExtendedSetLike
object.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a
ExtendedSetLikeConstructor
function; otherwise, false.
Guards
function isReadonlyCollection<T>(it: unknown): it is ReadonlyCollection<T>;Checks whether the provided value is a
ReadonlyCollection
object. The ReadonlyCollection interface is the minimum requirement for a
value to be used in the composition methods found in ExtendedSetLike
implementations, such as union, intersection, difference, and
symmetricDifference.
This type is the bare minimal requirement for a value to be considered a
"set-like" object in JavaScript, and only requires the has, keys, and size
members to be present. As such, native Set objects and also native Map
objects both qualify as ReadonlyCollection objects. For a more specific check,
see isSetLike or
isExtendedSetLike,
which check for the full API of a Set object, with or without the composition
methods added by the TC39 proposal, respectively.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a
ReadonlyCollection
object; otherwise, false.
Guards
function isReadonlyCollectionConstructor(
it: unknown,
): it is ReadonlyCollectionConstructor;Checks if a given value appears to be a
ReadonlyCollectionConstructor
function, including a prototype property that appears to be a
ReadonlyCollection
object.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value appears to be a
ReadonlyCollectionConstructor
function; otherwise, false.
Guards
function isSetLike<T>(it: unknown): it is SetLike<T>;Checks whether the provided value is a
SetLike object. The SetLike
interface is the base implementation of a ExtendedSetLike object, without any
additional composition methods like union or intersection.
This type is the shape of the native Set object in JavaScript prior to the
introduction of the TC39 Proposal for Set Methods, which added the composition
methods to the API.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a SetLike
object; otherwise, false.
Guards
function isSetLikeConstructor(it: unknown): it is SetLikeConstructor;Checks if a given value appears to be a
SetLikeConstructor
function, including a prototype property that appears to be a
SetLike object.
| Name | Info |
|---|---|
it |
The value to check. |
true if the value is a
SetLikeConstructor
function; otherwise, false.
Guards
export type SupportedSetLike<T = unknown> =
Exclude<keyof ExtendedSetLike<T>, keyof SetLike<T>> extends
keyof globalThis.Set<T> ? ExtendedSetLike<T> : SetLike<T>;This type represents either the full
ExtendedSetLike
interface, or the SetLike interface,
depending on whether the current environment supports composition methods
introduced by the TC39 Set Methods Proposal.
If the current environment supports the composition methods, this type will
resolve to the
ExtendedSetLike
interface. Otherwise, it will resolve to the
SetLike interface.
-
T(default:unknown)
-
SupportedSetLikeConstructorfor a similar type that represents the constructor function for the supported set-like object.
export type SupportedSetLikeConstructor =
Exclude<keyof ExtendedSetLikeConstructor, keyof SetLikeConstructor> extends
keyof globalThis.SetConstructor ? ExtendedSetLikeConstructor
: SetLikeConstructor;This type represents either the full
ExtendedSetLikeConstructor
interface, or the
SetLikeConstructor
interface, depending on whether the current environment supports composition
methods introduced by the TC39 Set Methods Proposal.
If the current environment supports the composition methods, this type will
resolve to the
ExtendedSetLikeConstructor
interface. Otherwise, it will resolve to the
SetLikeConstructor
interface.
-
SupportedSetLikefor a similar type that represents the full set-like object.
A ExtendedSetLike object is a collection of values, where each value may only
occur once. The values in a ExtendedSetLike can be either primitive values or
object references. The keys of a ExtendedSetLike are the same as the values.
-
T(default:unknown)
union<U>(
other: ReadonlyCollection<U>,
): ExtendedSetLike<T | U>;| Name | Info |
|---|---|
other |
The other set-like object to merge with this one. |
a new ExtendedSetLike
object containing all the elements in this
ExtendedSetLike object
and also all the elements in the other.
intersection<U>(
other: ReadonlyCollection<U>,
): ExtendedSetLike<T & U>;| Name | Info |
|---|---|
other |
The other set-like object to intersect with this one. |
a new ExtendedSetLike
object containing all the elements which are both in this
ExtendedSetLike object
and in the other.
difference<U>(
other: ReadonlyCollection<U>,
): ExtendedSetLike<T>;| Name | Info |
|---|---|
other |
The other set-like object to compare with this one. |
a new ExtendedSetLike
object containing all the elements in this
ExtendedSetLike object
which are not also in the other.
symmetricDifference<U>(
other: ReadonlyCollection<U>,
): ExtendedSetLike<T | U>;| Name | Info |
|---|---|
other |
The other set-like object to compare with this one. |
a new ExtendedSetLike object containing all the elements which are in either
this ExtendedSetLike
object or in the other, but not in both.
isSubsetOf<U>(
other: ReadonlyCollection<U>,
): boolean;| Name | Info |
|---|---|
other |
The other set-like object to compare with this one. |
a boolean indicating whether all the elements in this
ExtendedSetLike object
are also in the other.
isSupersetOf<U>(
other: ReadonlyCollection<U>,
): boolean;| Name | Info |
|---|---|
other |
The other set-like object to compare with this one. |
a boolean indicating whether all the elements in the
other are also in this
ExtendedSetLike
object.
isDisjointFrom<U>(
other: ReadonlyCollection<U>,
): boolean;| Name | Info |
|---|---|
other |
The other set-like object to compare with this one. |
a boolean indicating whether this
ExtendedSetLike object
has no elements in common with the other.
Represents a constructor function for an
ExtendedSetLike
object.
readonly prototype: ExtendedSetLike<any>;Set-like objects are collections of unique values (each value may only occur
once). The ReadonlyCollection interface defines the bare minimum requirements
for an object to be considered "set-like" in JavaScript; that is, it must have:
- a
hasmethod, which tests whether a given value is present in the set, returning a boolean value indicating the result. - a
keysmethod, which returns anIterableIteratorfor the keys present in the set. Since set collections are keyed by their values, thekeysmethod actually iterates over the values in the set. - a read-only
sizeproperty (getter), which returns the number of values in the set at any given time.
This interface the base for the SetLike interface (hence its name), which
extends it with additional methods like add, delete, clear, forEach,
values, and entries to provide a more complete API for working with Set-
like collections in JavaScript. Prior to the TC39 Proposal for Set Methods, the
SetLike interface was the shape of the native Set API in JavaScript.
Following the introduction of the TC39 Proposal for Set Methods, the methods for
set composition (union, intersection, difference, etc.) were added to the
Set API, which necessitated the creation of the ExtendedSetLike interface to
represent the full API for set-like collections in JavaScript.
Those methods require their arguments to implement the
ReadonlyCollection
interface, rather than the full
SetLike or
ExtendedSetLike. This
means you can call Set.prototype.union with a Set, Map, or even an
IterableWeakSet object, since they all implement the ReadonlyCollection API.
-
T(default:unknown)
readonly size: number;The number of elements in the collection.
has(value: T): boolean;Tests whether a given value is present in the collection.
| Name | Info |
|---|---|
value |
The value to lookup. |
true if the value is in the collection; otherwise, false.
keys(): IterableIterator<T>;Gets an IterableIterator for the keys present in the collection.
An iterator of the keys in the collection.
Represents a constructor function for a
ReadonlyCollection
object, which is the base implementation of a
ExtendedSetLike
object, without any of the additional composition methods like union or
intersection.
-
ExtendedSetLikefor the full interface with composition methods. -
SetLikefor the core interface without composition methods.
readonly prototype: ReadonlyCollection<unknown>;Represents the core functionality of a SetLike object, which is the base
implementation of a
ExtendedSetLike
object, without any additional composition methods (union, intersection,
difference, etc). This was the native Set API prior to the TC39 Set Methods
Proposal's introduction.
- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
-
ExtendedSetLikefor the full interface with composition methods. -
SetLikeConstructorfor the constructor interface.
-
T(default:unknown)
readonly size: number;The number of elements in the collection.
readonly [Symbol.toStringTag]: string;add(value: T): this;Adds the given value to the collection, if it does not already exist.
| Name | Info |
|---|---|
value |
The value to add. |
The collection.
has(value: T): boolean;Tests whether a key is present in the collection.
| Name | Info |
|---|---|
value |
The key to lookup. |
true if the value is in the collection; otherwise, false.
clear(): void;Removes all values from the collection.
delete(value: T): boolean;Removes a value from the collection.
| Name | Info |
|---|---|
value |
The vakue to remove. |
true if the operation was successful; otherwise, false.
forEach<This = void>(
cb: (this: This, value: T, value2: T, set: this) => void,
thisArg?: This,
): void;Executes a provided function once per each entry in the collection. The callback
is invoked with the current value for both the first and second arguments (to
maintain a similar signature as forEach on other iterable objects like Map
and Array).
| Name | Info |
|---|---|
cb |
The callback to execute. |
thisArg |
The value to use as this when executing the callback. |
Nothing.
keys(): IterableIterator<T>;an Iterable of the values in the collection.
values(): IterableIterator<T>;an IterableIterator for the values present in the collection.
entries(): IterableIterator<
[T, T]
>;an IterableIterator of the entries present in the collection. Each entry is a
tuple containing the key and value for each element.
[Symbol.iterator](): IterableIterator<
T
>;Returns an iterator of the values in the
set.
Represents a constructor function for a
SetLike object, which is the base
implementation of a
ExtendedSetLike
object, without any of the additional composition methods like union or
intersection.
-
ExtendedSetLikefor the full interface with composition methods. -
SetLikefor the core interface without composition methods.
readonly prototype: SetLike<any>;