Skip to content

Commit

Permalink
check type first, then name
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouyang committed Nov 16, 2016
1 parent b7002d4 commit 9f933a0
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 2 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ describe('union type', function() {
describe('predicate', function() {
it('can use predicate to check type', function() {
var Maybe = Type({Just: [T], Nothing: []});
var OtherMaybe = Type({Just: [T]});
var just1 = Maybe.Just(1)
assert.equal(Maybe.isJust(just1), true);
assert.equal(Maybe.isNothing(just1), false);
assert.equal(Maybe.isNothing(just1), false);
assert.equal(OtherMaybe.isJust(just1), false);
})
});
describe('type methods', function() {
Expand Down
2 changes: 1 addition & 1 deletion union-type.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function constructor(group, name, fields) {
}
group[name] = curryN(keys.length, construct);
group['is' + name] = function(value) {
return name === value._name
return group.prototype.isPrototypeOf(value) && name === value._name
}
if (keys !== undefined) {
group[name+'Of'] = function(obj) {
Expand Down

0 comments on commit 9f933a0

Please sign in to comment.