{"action":"opened","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/22025","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/22025/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/22025/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/22025/events","html_url":"https://github.com/Microsoft/TypeScript/issues/22025","id":298129721,"number":22025,"title":"Referring to anonymous type parameters (captured via 'any') of generics leads to silent any coercition.","user":{"login":"sledorze","id":416760,"avatar_url":"https://avatars2.githubusercontent.com/u/416760?v=4","gravatar_id":"","url":"https://api.github.com/users/sledorze","html_url":"https://github.com/sledorze","followers_url":"https://api.github.com/users/sledorze/followers","following_url":"https://api.github.com/users/sledorze/following{/other_user}","gists_url":"https://api.github.com/users/sledorze/gists{/gist_id}","starred_url":"https://api.github.com/users/sledorze/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sledorze/subscriptions","organizations_url":"https://api.github.com/users/sledorze/orgs","repos_url":"https://api.github.com/users/sledorze/repos","events_url":"https://api.github.com/users/sledorze/events{/privacy}","received_events_url":"https://api.github.com/users/sledorze/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-02-18T23:31:54Z","updated_at":"2018-02-18T23:31:54Z","closed_at":null,"author_association":"NONE","body":"**TypeScript Version:**  2.7.2 and 2.8.0-dev.20180217\r\n\r\n<!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\nSearch Terms: any, capture, \r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Foo<T> {\r\n  t: T\r\n}\r\ntype TFoo<F extends Foo<any>> = F['t']\r\n\r\nconst bar = <Q extends Foo<any>>(f: Q): TFoo<Q> => {\r\n  return f.t\r\n}\r\n\r\nconst bar2 = <Q extends Foo<any>>(f: Q): TFoo<Q> => {\r\n  return [f.t] // wrong type not caught by compiler\r\n}\r\n\r\nconst foo1: Foo<number> = {\r\n  t: 45\r\n}\r\n\r\nconst foo2: Foo<number[]> = {\r\n  t: [45]\r\n}\r\n\r\nbar(foo1) // number\r\nbar(foo2) // number[]\r\n\r\nbar2(foo1) // number !!!  (but in reality it returns a number[])\r\nbar2(foo2) // number[] !!!  (but in reality it returns a number[][])\r\nWebpack, etc.\r\n```\r\n\r\n**Expected behavior:**\r\nI KNOW that from the types, this behaviour might be expected.\r\nHowever, I think that the pattern exhibited here is a common one and the only one I know of to be able to abstract over generic types **without** having to specify those types explicitely (which leads to other variance issues in specific cases).\r\n\r\nI would have loved to have an error when implementing bar2, like it does if I do:\r\n\r\n```ts\r\nconst bar2 = <X, Q extends Foo<T>>(f: Q): TFoo<Q> => {\r\n  return [f.t] // Type 'X[]' is not assignable to type 'Q[\"t\"]'.  Type 'X[]' is not assignable to type 'X'.\r\n}\r\n```\r\nit may be:\r\n\r\n```ts\r\nconst bar2 = <Q extends Foo<any>>(f: Q): TFoo<Q> => {\r\n  return [f.t] // Type 'Q[\"t\"][]' is not assignable to type 'Q[\"t\"]'.\r\n}\r\n```\r\n\r\n\r\n**Actual behavior:**\r\n\r\nThere's no compiler error\r\n\r\n**Related Issues:**\r\n\r\nhttps://github.com/gcanti/io-ts-types/issues/18\r\n\r\n"}}
{"actor":{"display_login":"sledorze"}}