diff --git a/implementations/javascript/packages/core/src/jsdictionary.ts b/implementations/javascript/packages/core/src/jsdictionary.ts index 8b00da7..3aebfa7 100644 --- a/implementations/javascript/packages/core/src/jsdictionary.ts +++ b/implementations/javascript/packages/core/src/jsdictionary.ts @@ -1,5 +1,4 @@ -import { Equivalence, IsMap, _iterMap } from './flex'; -import { Dictionary, DictionaryType } from './dictionary'; +import { Equivalence, _iterMap } from './flex'; export interface JsDictionary { [key: string]: V; @@ -7,9 +6,12 @@ export interface JsDictionary { export namespace JsDictionary { export function isJsDictionary(x: any): x is JsDictionary { - // We accept only literal objects and objects created via `new Object` - // as dictionaries. - return Object.getPrototypeOf(Object.getPrototypeOf(x ?? false)) === null; + // We accept only literal objects and objects created via `new Object` as dictionaries. + // Furthermore, we require no function-valued `__as_preserve__` property to exist. + return typeof x === 'object' + && x !== null + && Object.getPrototypeOf(Object.getPrototypeOf(x)) === null + && typeof x.__as_preserve__ !== 'function'; } export function from(entries: Iterable<[symbol, V]>): JsDictionary {