Another small refinement
This commit is contained in:
parent
99d1acdec7
commit
6bc159e3c6
|
@ -1,5 +1,4 @@
|
|||
import { Equivalence, IsMap, _iterMap } from './flex';
|
||||
import { Dictionary, DictionaryType } from './dictionary';
|
||||
import { Equivalence, _iterMap } from './flex';
|
||||
|
||||
export interface JsDictionary<V> {
|
||||
[key: string]: V;
|
||||
|
@ -7,9 +6,12 @@ export interface JsDictionary<V> {
|
|||
|
||||
export namespace JsDictionary {
|
||||
export function isJsDictionary<V>(x: any): x is JsDictionary<V> {
|
||||
// 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<V>(entries: Iterable<[symbol, V]>): JsDictionary<V> {
|
||||
|
|
Loading…
Reference in New Issue