diff --git a/src/validation/jsonType.ts b/src/validation/jsonType.ts index 9df64a31..42c157f8 100644 --- a/src/validation/jsonType.ts +++ b/src/validation/jsonType.ts @@ -18,10 +18,7 @@ function isJsonObject(value: unknown): value is JsonObject { } function isPlainObject(value: unknown): value is object { - return typeof value === 'object' // exclude primitives - && value !== null // exclude nulls - && value.constructor === Object // exclude instances (Array, DOM, ...) - && Object.prototype.toString.call(value) === '[object Object]'; // exclude build-in like Math + return Object.prototype.toString.call(value) === '[object Object]'; } type JsonObjectDefinition = { diff --git a/test/validation/jsonType.test.ts b/test/validation/jsonType.test.ts index a7168db5..6989d1ba 100644 --- a/test/validation/jsonType.test.ts +++ b/test/validation/jsonType.test.ts @@ -68,6 +68,7 @@ describe('A JSON object type', () => { [['foo', 'bar'], false], [{foo: 'bar'}, true], [new Object('foo'), false], + [new Object(), true], ])('should determine whether the type of a given value is valid', (value: any, expected: boolean) => { expect(new JsonObjectType().isValidType(value)).toBe(expected); });