Repository: gcanti/tcomb (js)

Issue:
mixing types and classes in a union throws
Failing test case

```js
import t from 'tcomb'

class A {}
const U = t.union([t.Boolean, A], 'U')
U(new A())
```

Pull request description:
mixing types and classes in a union throws, fix #232

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 83af504..75c7907 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,11 @@
 **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.
 
+# 3.2.8
+
+- **Bug Fix**
+  - mixing types and classes in a union throws, fix #232 (@gcanti)
+
 # 3.2.7
 
 - **Bug Fix**
diff --git a/lib/union.js b/lib/union.js
index bc640f7..5a8be20 100644
--- a/lib/union.js
+++ b/lib/union.js
@@ -7,7 +7,6 @@ var isArray = require('./isArray');
 var create = require('./create');
 var is = require('./is');
 var forbidNewOperator = require('./forbidNewOperator');
-var isType = require('./isType');
 var isUnion = require('./isUnion');
 var isNil = require('./isNil');
 
@@ -43,7 +42,7 @@ function union(types, name) {
         forbidNewOperator(this, Union);
       }
       path = path || [displayName];
-      assert(isType(type), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/') + ' (no constructor returned by dispatch)'; });
+      assert(isFunction(type), function () { return 'Invalid value ' + assert.stringify(value) + ' supplied to ' + path.join('/') + ' (no constructor returned by dispatch)'; });
       path[path.length - 1] += '(' + getTypeName(type) + ')';
     }
 
diff --git a/package.json b/package.json
index 798724d..99da284 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
 {
   "name": "tcomb",
-  "version": "3.2.7",
+  "version": "3.2.8",
   "description": "Type checking and DDD for JavaScript",
   "main": "index.js",
   "typings": "index.d.ts",


Test patch:
diff --git a/test/union.js b/test/union.js
index 5acc3b9..b9e0f91 100644
--- a/test/union.js
+++ b/test/union.js
@@ -172,6 +172,14 @@ describe('t.union(types, [name])', function () {
       });
     });
 
+    it('should handle constructors', function () {
+      function A() {}
+      var U = t.union([t.Boolean, A], 'U');
+      assert.doesNotThrow(function () {
+        U(new A());
+      });
+    });
+
   });
 
   describe('update(instance, patch)', function () {