{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3315","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3315/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3315/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3315/events","html_url":"https://github.com/Microsoft/TypeScript/issues/3315","id":82945605,"number":3315,"title":"Distinguish between primitive and object types in generic type constraints?","user":{"login":"sccolbert","id":137289,"avatar_url":"https://avatars.githubusercontent.com/u/137289?v=3","gravatar_id":"","url":"https://api.github.com/users/sccolbert","html_url":"https://github.com/sccolbert","followers_url":"https://api.github.com/users/sccolbert/followers","following_url":"https://api.github.com/users/sccolbert/following{/other_user}","gists_url":"https://api.github.com/users/sccolbert/gists{/gist_id}","starred_url":"https://api.github.com/users/sccolbert/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sccolbert/subscriptions","organizations_url":"https://api.github.com/users/sccolbert/orgs","repos_url":"https://api.github.com/users/sccolbert/repos","events_url":"https://api.github.com/users/sccolbert/events{/privacy}","received_events_url":"https://api.github.com/users/sccolbert/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-30T23:40:02Z","updated_at":"2015-05-30T23:40:02Z","closed_at":null,"body":"With the introduction of WeakMap, the JS runtime now has [restrictions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakMap#Description) on where primitive types are disallowed. Is it possible (or planned) to have language support for discriminating from primitive types and the ability to constraint generic types based on that discrimination? \r\n\r\nFrom a [previous SO post I made](http://stackoverflow.com/questions/28122754/discriminate-between-empty-object-type-and-other-concrete-types), the answer seems to be \"no\". But taken in light of WeakMap requirements, perhaps it can be revisited?\r\n\r\n```javascript\r\nvar a = 1;\r\nundefined\r\n\r\nvar b = new Number(a);\r\nundefined\r\n\r\nvar m = new WeakMap();\r\nundefined\r\n\r\nm.set(a, 1)\r\nVM674:2 Uncaught TypeError: Invalid value used as weak map key\r\n    at WeakMap.set (native)\r\n    at <anonymous>:2:3\r\n    at Object.InjectedScript._evaluateOn (<anonymous>:905:140)\r\n    at Object.InjectedScript._evaluateAndWrap (<anonymous>:838:34)\r\n    at Object.InjectedScript.evaluate (<anonymous>:694:21)(anonymous function) @ VM674:2InjectedScript._evaluateOn @ VM305:905InjectedScript._evaluateAndWrap @ VM305:838InjectedScript.evaluate @ VM305:694\r\n\r\nm.set(b, 1)\r\nWeakMap {Number {[[PrimitiveValue]]: 1} => 1}\r\n```"}}