{"action":"created","issue":{"url":"https://api.github.com/repos/gcanti/tcomb/issues/92","labels_url":"https://api.github.com/repos/gcanti/tcomb/issues/92/labels{/name}","comments_url":"https://api.github.com/repos/gcanti/tcomb/issues/92/comments","events_url":"https://api.github.com/repos/gcanti/tcomb/issues/92/events","html_url":"https://github.com/gcanti/tcomb/issues/92","id":70528966,"number":92,"title":"tcomb lists + es6 classes","user":{"login":"timoxley","id":43438,"avatar_url":"https://avatars.githubusercontent.com/u/43438?v=3","gravatar_id":"","url":"https://api.github.com/users/timoxley","html_url":"https://github.com/timoxley","followers_url":"https://api.github.com/users/timoxley/followers","following_url":"https://api.github.com/users/timoxley/following{/other_user}","gists_url":"https://api.github.com/users/timoxley/gists{/gist_id}","starred_url":"https://api.github.com/users/timoxley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timoxley/subscriptions","organizations_url":"https://api.github.com/users/timoxley/orgs","repos_url":"https://api.github.com/users/timoxley/repos","events_url":"https://api.github.com/users/timoxley/events{/privacy}","received_events_url":"https://api.github.com/users/timoxley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-04-23T22:28:54Z","updated_at":"2015-04-23T22:37:08Z","closed_at":null,"body":"tcomb lists don't currently play nice with es6 classes due to inability to invoke classes without `new`:\r\n\r\n```\r\n$ babel-node\r\n> const t = require('tcomb')\r\n> class Person extends t.struct({name: t.Str}) {}\r\n> const a = new Person({name: 'alice'})\r\n> const b = new Person({name: 3})\r\n/Users/timoxley/Projects/tests/tcomb-classes/node_modules/tcomb/index.js:15\r\n    throw new TypeError(message);\r\n          ^\r\nTypeError: Invalid argument `value` = `3` supplied to irreducible type `Str`\r\n    at Object.fail (/Users/timoxley/Projects/tests/tcomb-classes/node_modules/tcomb/index.js:15:11)\r\n    at assert (/Users/timoxley/Projects/tests/tcomb-classes/node_modules/tcomb/index.js:21:15)\r\n    at Irreducible (/Users/timoxley/Projects/tests/tcomb-classes/node_modules/tcomb/index.js:174:7)\r\n    at Person.Struct (/Users/timoxley/Projects/tests/tcomb-classes/node_modules/tcomb/index.js:260:21)\r\n    at new Person (repl:12:17)\r\n    at repl:3:9\r\n    at Object.exports.runInThisContext (vm.js:74:17)\r\n    at _eval (/usr/local/lib/node_modules/babel/bin/_babel-node:54:13)\r\n    at REPLServer.replEval (/usr/local/lib/node_modules/babel/bin/_babel-node:136:14)\r\n    at bound (domain.js:254:14)\r\n> const People = t.list(Person)\r\n> const c = new People([{name: 'cathy'}])\r\nrepl:3\r\nnce, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeEr\r\n                                                                    ^\r\nTypeError: Cannot call a class as a function\r\n    at _classCallCheck (repl:3:106)\r\n    at Person (repl:9:5)\r\n    at new List (/Users/timoxley/Projects/tests/tcomb-classes/node_modules/tcomb/index.js:513:18)\r\n    at repl:3:9\r\n    at Object.exports.runInThisContext (vm.js:74:17)\r\n    at _eval (/usr/local/lib/node_modules/babel/bin/_babel-node:54:13)\r\n    at REPLServer.replEval (/usr/local/lib/node_modules/babel/bin/_babel-node:136:14)\r\n    at bound (domain.js:254:14)\r\n    at REPLServer.runBound [as eval] (domain.js:267:12)\r\n    at REPLServer.<anonymous> (repl.js:279:12)\r\n>\r\n```\r\n\r\nCode in question:\r\n\r\n```js\r\n      for (var i = 0, len = value.length ; i < len ; i++ ) {\r\n        var actual = value[i];\r\n        arr.push(type(actual, mut)); // <– calling `type` without `new`\r\n      }\r\n```\r\n\r\nNot sure good solution here though since AFAIK it's impossible to detect whether something should be invoked with `new` or not.\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/gcanti/tcomb/issues/comments/95736550","html_url":"https://github.com/gcanti/tcomb/issues/92#issuecomment-95736550","issue_url":"https://api.github.com/repos/gcanti/tcomb/issues/92","id":95736550,"user":{"login":"timoxley","id":43438,"avatar_url":"https://avatars.githubusercontent.com/u/43438?v=3","gravatar_id":"","url":"https://api.github.com/users/timoxley","html_url":"https://github.com/timoxley","followers_url":"https://api.github.com/users/timoxley/followers","following_url":"https://api.github.com/users/timoxley/following{/other_user}","gists_url":"https://api.github.com/users/timoxley/gists{/gist_id}","starred_url":"https://api.github.com/users/timoxley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timoxley/subscriptions","organizations_url":"https://api.github.com/users/timoxley/orgs","repos_url":"https://api.github.com/users/timoxley/repos","events_url":"https://api.github.com/users/timoxley/events{/privacy}","received_events_url":"https://api.github.com/users/timoxley/received_events","type":"User","site_admin":false},"created_at":"2015-04-23T22:37:08Z","updated_at":"2015-04-23T22:37:08Z","body":"Actually, thinking on this any code passed as the Type that isn't a constructor is unlikely to have specific requirements about `thisArg` anyway so it should be safe to just invoke `new type(actual, mut)`"}}