Skip to content

Commit 2813cc5

Browse files
committed
fix regression in v2.1.2
1 parent dc25290 commit 2813cc5

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
1515
high state of flux, you're at risk of it changing without notice.
1616

17-
# 2.1.2
17+
# 2.1.3
1818

1919
- **Polish**
2020
- remove useless `hasOwnProperty` calls, closes #423 (@gcanti)

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "io-ts",
3-
"version": "2.1.2",
3+
"version": "2.1.3",
44
"description": "TypeScript compatible runtime type system for IO validation",
55
"files": [
66
"lib",

src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,8 @@ export const type = <P extends Props>(props: P, name: string = getInterfaceTypeN
798798
if (UnknownRecord.is(u)) {
799799
for (let i = 0; i < len; i++) {
800800
const k = keys[i]
801-
if (!types[i].is(u[k])) {
801+
const uk = u[k]
802+
if ((uk === undefined && !hasOwnProperty.call(u, k)) || !types[i].is(uk)) {
802803
return false
803804
}
804805
}

test/type.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ describe('type', () => {
3131
assert.strictEqual(T.is([]), false)
3232
})
3333

34+
// #434
35+
it('should return `false` on missing fields', () => {
36+
const T = t.type({ a: t.unknown })
37+
assert.strictEqual(T.is({}), false)
38+
})
39+
3440
it('should allow additional properties', () => {
3541
const T = t.type({ a: t.string })
3642
assert.strictEqual(T.is({ a: 'a', b: 1 }), true)

0 commit comments

Comments
 (0)