Skip to content

Commit

Permalink
fix regression in v2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Apr 3, 2020
1 parent dc25290 commit 2813cc5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
**Note**: Gaps between patch versions are faulty/broken releases. **Note**: A feature tagged as Experimental is in a
high state of flux, you're at risk of it changing without notice.

# 2.1.2
# 2.1.3

- **Polish**
- remove useless `hasOwnProperty` calls, closes #423 (@gcanti)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "io-ts",
"version": "2.1.2",
"version": "2.1.3",
"description": "TypeScript compatible runtime type system for IO validation",
"files": [
"lib",
Expand Down
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,8 @@ export const type = <P extends Props>(props: P, name: string = getInterfaceTypeN
if (UnknownRecord.is(u)) {
for (let i = 0; i < len; i++) {
const k = keys[i]
if (!types[i].is(u[k])) {
const uk = u[k]
if ((uk === undefined && !hasOwnProperty.call(u, k)) || !types[i].is(uk)) {
return false
}
}
Expand Down
6 changes: 6 additions & 0 deletions test/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ describe('type', () => {
assert.strictEqual(T.is([]), false)
})

// #434
it('should return `false` on missing fields', () => {
const T = t.type({ a: t.unknown })
assert.strictEqual(T.is({}), false)
})

it('should allow additional properties', () => {
const T = t.type({ a: t.string })
assert.strictEqual(T.is({ a: 'a', b: 1 }), true)
Expand Down

0 comments on commit 2813cc5

Please sign in to comment.