Accept fewer `Object`s as `JsDictionary`
This commit is contained in:
parent
3093b89f0d
commit
99d1acdec7
|
@ -230,12 +230,7 @@ export namespace Dictionary {
|
|||
if (typeof x !== 'object' || x === null) return false;
|
||||
switch (x[DictionaryType]) {
|
||||
case 'Dictionary': return true;
|
||||
case void 0:
|
||||
if (Array.isArray(x)) return false;
|
||||
if (isEmbedded(x)) return false;
|
||||
if (Float.isFloat(x)) return false;
|
||||
if (Bytes.isBytes(x)) return false;
|
||||
return true;
|
||||
case void 0: return JsDictionary.isJsDictionary(x);
|
||||
default: return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,9 @@ export interface JsDictionary<V> {
|
|||
|
||||
export namespace JsDictionary {
|
||||
export function isJsDictionary<V>(x: any): x is JsDictionary<V> {
|
||||
return Dictionary.isDictionary(x) && (x as any)[DictionaryType] === void 0;
|
||||
// We accept only literal objects and objects created via `new Object`
|
||||
// as dictionaries.
|
||||
return Object.getPrototypeOf(Object.getPrototypeOf(x ?? false)) === null;
|
||||
}
|
||||
|
||||
export function from<V>(entries: Iterable<[symbol, V]>): JsDictionary<V> {
|
||||
|
|
Loading…
Reference in New Issue