Skip to content

Commit

Permalink
type-check the value returned by a custom reviver, fromJSON module
Browse files Browse the repository at this point in the history
  • Loading branch information
gcanti committed Jul 14, 2016
1 parent 06aa7a7 commit 97d03fe
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

- **Bug Fix**
- add support for class constructors, `fromJSON` module (@gcanti)
- type-check the value returned by a custom reviver, `fromJSON` module (@gcanti)

# v3.2.6

Expand Down
2 changes: 1 addition & 1 deletion lib/fromJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function fromJSON(value, type) {
}

if (isFunction(type.fromJSON)) {
return type.fromJSON(value);
return type(type.fromJSON(value));
}

if (!isType(type)) {
Expand Down
4 changes: 2 additions & 2 deletions test/fromJSON.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ describe('fromJSON', function () {
it('should handle a static fromJSON function attached to the type', function () {
var MyType = t.refinement(t.String, function () { return true; });
MyType.fromJSON = function (s) {
return s.length;
return s + 'ok';
};
assert.equal(fromJSON('aaa', MyType), 3);
assert.equal(fromJSON('aaa', MyType), 'aaaok');
});

it('should handle class constructors', function () {
Expand Down

0 comments on commit 97d03fe

Please sign in to comment.