declare global { interface Set { toReadonly(): ReadonlySet; } } export class RuntimeReadonlySet implements ReadonlySet { public constructor( private readonly _wrap: Set, ) { } public forEach(callbackfn: (value: T, value2: T, set: ReadonlySet) => void, thisArg?: any): void { return this._wrap.forEach(callbackfn, thisArg); } public has(value: T): boolean { return this._wrap.has(value); } public get size(): number { return this._wrap.size; } public entries(): SetIterator<[T, T]> { return this._wrap.entries(); } public keys(): SetIterator { return this._wrap.keys(); } public values(): SetIterator { return this._wrap.values(); } public [Symbol.iterator](): SetIterator { return this._wrap[Symbol.iterator](); } } Set.prototype.toReadonly = function (): ReadonlySet { return new RuntimeReadonlySet(this); }