diff options
Diffstat (limited to 'cli/js/web/util.ts')
-rw-r--r-- | cli/js/web/util.ts | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/cli/js/web/util.ts b/cli/js/web/util.ts index 8d248ce1f..19a30a675 100644 --- a/cli/js/web/util.ts +++ b/cli/js/web/util.ts @@ -31,7 +31,7 @@ export function immutableDefine( Object.defineProperty(o, p, { value, configurable: false, - writable: false + writable: false, }); } @@ -53,3 +53,18 @@ export function hasOwnProperty<T>(obj: T, v: PropertyKey): boolean { } return Object.prototype.hasOwnProperty.call(obj, v); } + +/** Returns whether o is iterable. + * + * @internal */ +export function isIterable<T, P extends keyof T, K extends T[P]>( + o: T +): o is T & Iterable<[P, K]> { + // checks for null and undefined + if (o == null) { + return false; + } + return ( + typeof ((o as unknown) as Iterable<[P, K]>)[Symbol.iterator] === "function" + ); +} |