{"action":"created","issue":{"url":"https://api.github.com/repos/gcanti/tcomb/issues/197","repository_url":"https://api.github.com/repos/gcanti/tcomb","labels_url":"https://api.github.com/repos/gcanti/tcomb/issues/197/labels{/name}","comments_url":"https://api.github.com/repos/gcanti/tcomb/issues/197/comments","events_url":"https://api.github.com/repos/gcanti/tcomb/issues/197/events","html_url":"https://github.com/gcanti/tcomb/issues/197","id":152487554,"number":197,"title":"Determining supertypes/inheritence?","user":{"login":"R3D4C73D","id":10983817,"avatar_url":"https://avatars.githubusercontent.com/u/10983817?v=3","gravatar_id":"","url":"https://api.github.com/users/R3D4C73D","html_url":"https://github.com/R3D4C73D","followers_url":"https://api.github.com/users/R3D4C73D/followers","following_url":"https://api.github.com/users/R3D4C73D/following{/other_user}","gists_url":"https://api.github.com/users/R3D4C73D/gists{/gist_id}","starred_url":"https://api.github.com/users/R3D4C73D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/R3D4C73D/subscriptions","organizations_url":"https://api.github.com/users/R3D4C73D/orgs","repos_url":"https://api.github.com/users/R3D4C73D/repos","events_url":"https://api.github.com/users/R3D4C73D/events{/privacy}","received_events_url":"https://api.github.com/users/R3D4C73D/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/gcanti/tcomb/labels/discussion","name":"discussion","color":"fef2c0"},{"url":"https://api.github.com/repos/gcanti/tcomb/labels/help%20wanted","name":"help wanted","color":"159818"},{"url":"https://api.github.com/repos/gcanti/tcomb/labels/new%20feature","name":"new feature","color":"5319e7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":12,"created_at":"2016-05-02T06:12:08Z","updated_at":"2016-05-29T23:50:25Z","closed_at":null,"body":"Is there a way to tell if type A is a subtype of type B programmatically?  For example...\r\n\r\n```es6\r\nconst Integer = t.refinement(t.Number, (n) => n % 1 === 0, 'Integer');\r\nInteger.isSubtypeOf(t.Number);  // true\r\nInteger.isSubtypeOf(t.String);  // false\r\n```\r\n\r\nMy use-case is that I'm using tcomb to determine whether it's valid to assign a value of type A to a variable of type B.  Obviously, if I had an explicit value in mind, I could just do `t.Number.is(x)`, but in my case, I don't have an explicit value.  I have two variables, one of type A and one of type B.  I'm going to be assigning the hypothetical value of A to B, but I don't know what that value will be at runtime.\r\n\r\nIf I just did regular comparison (`typeA === typeB`) that would work for exact matches, but what about when type A is a subtype of type B?  An exact match won't catch it, but they're still technically compatible going from a more specific type to a more general type.\r\n\r\n```es6\r\nvar a;  // type Integer\r\nvar b;  // type t.Number\r\n\r\n// Some stuff happens that assigns a value to a\r\n\r\n// If I check for typeof a === typeof b, this will seem to be invalid.\r\n// But all Integers are valid Numbers.\r\nb = a;\r\n```\r\n\r\nAny ideas on how to implement this?  Perhaps walking through `meta.type` and `meta.types`?  Should this be incorporated into the library or should this just be part of my project's code?\r\n\r\nThanks for all the work on tcomb, @gcanti.  It's been a very valuable tool."},"comment":{"url":"https://api.github.com/repos/gcanti/tcomb/issues/comments/222390023","html_url":"https://github.com/gcanti/tcomb/issues/197#issuecomment-222390023","issue_url":"https://api.github.com/repos/gcanti/tcomb/issues/197","id":222390023,"user":{"login":"R3D4C73D","id":10983817,"avatar_url":"https://avatars.githubusercontent.com/u/10983817?v=3","gravatar_id":"","url":"https://api.github.com/users/R3D4C73D","html_url":"https://github.com/R3D4C73D","followers_url":"https://api.github.com/users/R3D4C73D/followers","following_url":"https://api.github.com/users/R3D4C73D/following{/other_user}","gists_url":"https://api.github.com/users/R3D4C73D/gists{/gist_id}","starred_url":"https://api.github.com/users/R3D4C73D/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/R3D4C73D/subscriptions","organizations_url":"https://api.github.com/users/R3D4C73D/orgs","repos_url":"https://api.github.com/users/R3D4C73D/repos","events_url":"https://api.github.com/users/R3D4C73D/events{/privacy}","received_events_url":"https://api.github.com/users/R3D4C73D/received_events","type":"User","site_admin":false},"created_at":"2016-05-29T23:50:25Z","updated_at":"2016-05-29T23:50:25Z","body":"I agree about instrumented functions.  I felt weird adding that code in there.  However, I guess that's a separate feature request.  I'm unaware of any way to detect instrumented functions from regular functions without knowing implementation details of the library.  Also, once you've confirmed you have an instrumented function, I'm unaware of a way to get the type from the function.\r\n\r\nOne big difference I've noticed between your implementation and mine is that you're doing a bunch of comparison between kind and string literals.  I preferred going for separate functions to detect if something is of a type.  The reasoning for that was so there was one canonical place in the code that does that detection.  That way, if later down the line you should decide to change what that string literal is, there's only one place in the code where you have to change that comparison instead of the `isSubsetOf` code, and the `fromJSON` code, and wherever else."}}
{"actor":{"display_login":"R3D4C73D"}}