diff options
Diffstat (limited to 'cli/js/web/util.ts')
-rw-r--r-- | cli/js/web/util.ts | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/cli/js/web/util.ts b/cli/js/web/util.ts index 2d63b4d60..32e73c443 100644 --- a/cli/js/web/util.ts +++ b/cli/js/web/util.ts @@ -11,6 +11,7 @@ export type TypedArray = | Float32Array | Float64Array; +// @internal export function isTypedArray(x: unknown): x is TypedArray { return ( x instanceof Int8Array || @@ -54,19 +55,8 @@ export function immutableDefine( }); } -// Returns values from a WeakMap to emulate private properties in JavaScript -export function getPrivateValue< - K extends object, - V extends object, - W extends keyof V ->(instance: K, weakMap: WeakMap<K, V>, key: W): V[W] { - if (weakMap.has(instance)) { - return weakMap.get(instance)![key]; - } - throw new TypeError("Illegal invocation"); -} - -export function hasOwnProperty<T>(obj: T, v: PropertyKey): boolean { +// @internal +export function hasOwnProperty(obj: unknown, v: PropertyKey): boolean { if (obj == null) { return false; } @@ -87,3 +77,19 @@ export function isIterable<T, P extends keyof T, K extends T[P]>( typeof ((o as unknown) as Iterable<[P, K]>)[Symbol.iterator] === "function" ); } + +// eslint-disable-next-line @typescript-eslint/no-explicit-any +interface GenericConstructor<T = any> { + prototype: T; +} + +/** A helper function which ensures accessors are enumerable, as they normally + * are not. */ +export function defineEnumerableProps( + Ctor: GenericConstructor, + props: string[] +): void { + for (const prop of props) { + Reflect.defineProperty(Ctor.prototype, prop, { enumerable: true }); + } +} |