From f55c9d62d36a50e67b4e8568ec9b3398bb09e632 Mon Sep 17 00:00:00 2001 From: Rahul Yadav Date: Tue, 8 Oct 2024 10:19:46 +0530 Subject: [PATCH] fix: add polyfills for Set.prototype.isSubsetOf (#119) --- src/lib/polyfills.ts | 27 +++++++++++++++++++++++++++ src/pages/_app.tsx | 1 + 2 files changed, 28 insertions(+) create mode 100644 src/lib/polyfills.ts diff --git a/src/lib/polyfills.ts b/src/lib/polyfills.ts new file mode 100644 index 0000000..1beba00 --- /dev/null +++ b/src/lib/polyfills.ts @@ -0,0 +1,27 @@ +/* eslint-disable @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-explicit-any */ + +// Extend the Set prototype to include isSubsetOf +interface Set { + isSubsetOf(otherSet: Set): boolean; +} + +if (!(Set.prototype as any).isSubsetOf) { + (Set.prototype as any).isSubsetOf = function ( + this: Set, + otherSet: Set, + ): boolean { + // @ts-expect-error - TS doesn't know that this is a Set + for (const elem of this) { + // @ts-expect-error - TS doesn't know that otherSet is a Set + if (!otherSet.has(elem)) { + return false; + } + } + return true; + }; +} + +/* eslint-enable */ + +// Add an empty export statement to ensure it's treated as a module +export {}; diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 0271819..c90414e 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -11,6 +11,7 @@ import type { AppProps } from 'next/app'; import Head from 'next/head'; import { useEffect } from 'react'; import { RecoilRoot } from 'recoil'; +import '../lib/polyfills'; mixpanel.init(AppConfig.analytics.MIXPANEL_TOKEN, { debug: false,