From 9f933a0faaada42d0f5bc8db8e53d99ce08f3103 Mon Sep 17 00:00:00 2001 From: Jichao Ouyang Date: Wed, 16 Nov 2016 15:44:49 +0800 Subject: [PATCH] check type first, then name --- test/index.js | 2 ++ union-type.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 59d4876..54af483 100644 --- a/test/index.js +++ b/test/index.js @@ -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() { diff --git a/union-type.js b/union-type.js index cd9b7ea..d465e8b 100644 --- a/union-type.js +++ b/union-type.js @@ -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) {