-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfrom.ts
More file actions
27 lines (23 loc) · 741 Bytes
/
Copy pathfrom.ts
File metadata and controls
27 lines (23 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import type { PrototypeStruct } from '../index.js';
interface WeakSetFrom {
from<K extends object>(mapEntries: K[]): WeakSet<K>;
}
export const from: PrototypeStruct = {
isStatic: true,
label: 'from',
fn: function weakSetFrom<K extends object>(mapEntries: K[]): WeakSet<K> {
if (!Array.isArray(mapEntries)) {
// tslint:disable-next-line: max-line-length
throw new TypeError(`Invalid WeakSet entries. Each WeakSet entry key must be an object`);
}
try {
return new WeakSet(mapEntries);
} catch (_) {
throw new TypeError(`WeakSet key must be an object`);
}
},
};
declare global {
// tslint:disable-next-line: no-empty-interface
interface WeakSetConstructor extends WeakSetFrom {}
}