Skip to content

Commit 4edbeb3

Browse files
mlegenhausengcanti
authored andcommitted
Object.prototype.toString removed from UnknownRecord.is
1 parent 7069ed0 commit 4edbeb3

File tree

3 files changed

+5
-8
lines changed

3 files changed

+5
-8
lines changed

src/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,7 @@ export class AnyDictionaryType extends Type<{ [key: string]: unknown }> {
992992
constructor() {
993993
super(
994994
'UnknownRecord',
995-
(u): u is { [key: string]: unknown } => {
996-
const s = Object.prototype.toString.call(u)
997-
return s === '[object Object]' || s === '[object Window]'
998-
},
995+
(u): u is { [key: string]: unknown } => u !== null && typeof u === 'object' && !Array.isArray(u),
999996
(u, c) => (this.is(u) ? success(u) : failure(u, c)),
1000997
identity
1001998
)

test/2.1.x/default-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ describe('UnknownRecord', () => {
88
const T = t.UnknownRecord
99
assert.strictEqual(T.is({}), true)
1010
assert.strictEqual(T.is({ a: 1 }), true)
11+
assert.strictEqual(T.is(new Number()), true)
1112
})
1213

1314
it('should return `false` for invalid objects', () => {
1415
const T = t.UnknownRecord
1516
assert.strictEqual(T.is(undefined), false)
16-
assert.strictEqual(T.is(new Number()), false)
1717
// #407
1818
assert.strictEqual(T.is([]), false)
1919
})
@@ -24,6 +24,7 @@ describe('UnknownRecord', () => {
2424
const T = t.UnknownRecord
2525
assertSuccess(T.decode({}))
2626
assertSuccess(T.decode({ a: 1 }))
27+
assertSuccess(T.decode(new Number()))
2728
})
2829

2930
it('should fail validating an invalid value', () => {
@@ -33,7 +34,6 @@ describe('UnknownRecord', () => {
3334
assertFailure(T, true, ['Invalid value true supplied to : UnknownRecord'])
3435
assertFailure(T, null, ['Invalid value null supplied to : UnknownRecord'])
3536
assertFailure(T, undefined, ['Invalid value undefined supplied to : UnknownRecord'])
36-
assertFailure(T, new Number(), ['Invalid value 0 supplied to : UnknownRecord'])
3737
// #407
3838
assertFailure(T, [], ['Invalid value [] supplied to : UnknownRecord'])
3939
})

test/2.1.x/record.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ describe('record', () => {
2828
const T1 = t.record(t.string, t.number)
2929
assert.strictEqual(T1.is({}), true)
3030
assert.strictEqual(T1.is({ a: 1 }), true)
31+
assert.strictEqual(T1.is(new Number()), true)
3132

3233
const T2 = t.record(t.string, NumberFromString)
3334
assert.strictEqual(T2.is({}), true)
@@ -42,7 +43,6 @@ describe('record', () => {
4243
const T1 = t.record(t.string, t.number)
4344
assert.strictEqual(T1.is({ a: 'a' }), false)
4445
assert.strictEqual(T1.is(null), false)
45-
assert.strictEqual(T1.is(new Number()), false)
4646
// #407
4747
assert.strictEqual(T1.is([]), false)
4848

@@ -73,6 +73,7 @@ describe('record', () => {
7373
const T = t.record(t.string, t.number)
7474
assertSuccess(T.decode({}))
7575
assertSuccess(T.decode({ a: 1 }))
76+
assertSuccess(T.decode(new Number()))
7677
})
7778

7879
it('should return the same reference while decoding isomorphic values', () => {
@@ -106,7 +107,6 @@ describe('record', () => {
106107
const T1 = t.record(t.string, t.number)
107108
assertFailure(T1, 1, ['Invalid value 1 supplied to : { [K in string]: number }'])
108109
assertFailure(T1, { aa: 's' }, ['Invalid value "s" supplied to : { [K in string]: number }/aa: number'])
109-
assertFailure(T1, new Number(), ['Invalid value 0 supplied to : { [K in string]: number }'])
110110
// #407
111111
assertFailure(T1, [], ['Invalid value [] supplied to : { [K in string]: number }'])
112112
// #407

0 commit comments

Comments
 (0)