Another small refinement
This commit is contained in:
parent
99d1acdec7
commit
6bc159e3c6
|
@ -1,5 +1,4 @@
|
||||||
import { Equivalence, IsMap, _iterMap } from './flex';
|
import { Equivalence, _iterMap } from './flex';
|
||||||
import { Dictionary, DictionaryType } from './dictionary';
|
|
||||||
|
|
||||||
export interface JsDictionary<V> {
|
export interface JsDictionary<V> {
|
||||||
[key: string]: V;
|
[key: string]: V;
|
||||||
|
@ -7,9 +6,12 @@ export interface JsDictionary<V> {
|
||||||
|
|
||||||
export namespace JsDictionary {
|
export namespace JsDictionary {
|
||||||
export function isJsDictionary<V>(x: any): x is JsDictionary<V> {
|
export function isJsDictionary<V>(x: any): x is JsDictionary<V> {
|
||||||
// We accept only literal objects and objects created via `new Object`
|
// We accept only literal objects and objects created via `new Object` as dictionaries.
|
||||||
// as dictionaries.
|
// Furthermore, we require no function-valued `__as_preserve__` property to exist.
|
||||||
return Object.getPrototypeOf(Object.getPrototypeOf(x ?? false)) === null;
|
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> {
|
export function from<V>(entries: Iterable<[symbol, V]>): JsDictionary<V> {
|
||||||
|
|
Loading…
Reference in New Issue