{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5949","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5949/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5949/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5949/events","html_url":"https://github.com/Microsoft/TypeScript/pull/5949","id":120599663,"number":5949,"title":"Type parameters as constraints","user":{"login":"ahejlsberg","id":4226954,"avatar_url":"https://avatars.githubusercontent.com/u/4226954?v=3","gravatar_id":"","url":"https://api.github.com/users/ahejlsberg","html_url":"https://github.com/ahejlsberg","followers_url":"https://api.github.com/users/ahejlsberg/followers","following_url":"https://api.github.com/users/ahejlsberg/following{/other_user}","gists_url":"https://api.github.com/users/ahejlsberg/gists{/gist_id}","starred_url":"https://api.github.com/users/ahejlsberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ahejlsberg/subscriptions","organizations_url":"https://api.github.com/users/ahejlsberg/orgs","repos_url":"https://api.github.com/users/ahejlsberg/repos","events_url":"https://api.github.com/users/ahejlsberg/events{/privacy}","received_events_url":"https://api.github.com/users/ahejlsberg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/cla-not-required","name":"cla-not-required","color":"009800"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2015-12-06T01:06:59Z","updated_at":"2015-12-10T20:44:55Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/5949","html_url":"https://github.com/Microsoft/TypeScript/pull/5949","diff_url":"https://github.com/Microsoft/TypeScript/pull/5949.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/5949.patch"},"body":"With this PR it becomes possible for a type parameter constraint to reference type parameters from the same type parameter list (this was previously an error). For example:\r\n\r\n```typescript\r\nfunction assign<T extends U, U>(target: T, source: U): T {\r\n    for (let id in source) {\r\n        target[id] = source[id];\r\n    }\r\n    return target;\r\n}\r\n\r\nlet x = { a: 1, b: 2, c: 3, d: 4 };\r\nassign(x, { b: 10, d: 20 });\r\nassign(x, { e: 0 });  // Error\r\n```\r\n\r\nA fancy term for this capability is [F-Bounded Polymorphism](https://en.wikipedia.org/wiki/Bounded_quantification#F-bounded_quantification).\r\n\r\nFixes #2304.\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/163744349","html_url":"https://github.com/Microsoft/TypeScript/pull/5949#issuecomment-163744349","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/5949","id":163744349,"user":{"login":"aleksey-bykov","id":937933,"avatar_url":"https://avatars.githubusercontent.com/u/937933?v=3","gravatar_id":"","url":"https://api.github.com/users/aleksey-bykov","html_url":"https://github.com/aleksey-bykov","followers_url":"https://api.github.com/users/aleksey-bykov/followers","following_url":"https://api.github.com/users/aleksey-bykov/following{/other_user}","gists_url":"https://api.github.com/users/aleksey-bykov/gists{/gist_id}","starred_url":"https://api.github.com/users/aleksey-bykov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aleksey-bykov/subscriptions","organizations_url":"https://api.github.com/users/aleksey-bykov/orgs","repos_url":"https://api.github.com/users/aleksey-bykov/repos","events_url":"https://api.github.com/users/aleksey-bykov/events{/privacy}","received_events_url":"https://api.github.com/users/aleksey-bykov/received_events","type":"User","site_admin":false},"created_at":"2015-12-10T20:44:55Z","updated_at":"2015-12-10T20:44:55Z","body":"by the way\r\n```typescript\r\n// test.ts\r\nexport function append<a, b extends a>(result: a[], value: a): a[] {\r\n    result.push(value);\r\n    return result;\r\n}\r\n```\r\n\r\ncompiles with\r\n```\r\nnode ./built/local/tsc.js --module commonjs test.ts \r\n```\r\n\r\nbut fails with\r\n```\r\nnode ./built/local/tsc.js --module commonjs --declaration test.ts \r\n```\r\nsaying\r\n```\r\ntest.ts(1,37): error TS4016: Type parameter 'b' of exported function has or is using private name 'a'.\r\n```"}}