{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3968","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3968/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3968/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3968/events","html_url":"https://github.com/Microsoft/TypeScript/pull/3968","id":96440724,"number":3968,"title":"Make a type with signatures not be a subtype of anyFunctionType","user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-07-21T23:42:40Z","updated_at":"2015-07-22T17:57:20Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/Microsoft/TypeScript/pulls/3968","html_url":"https://github.com/Microsoft/TypeScript/pull/3968","diff_url":"https://github.com/Microsoft/TypeScript/pull/3968.diff","patch_url":"https://github.com/Microsoft/TypeScript/pull/3968.patch"},"body":"Fixes #3954.\r\n\r\nHere is an example:\r\n```ts\r\nfunction f<T extends [(p1: number) => number]>(p: T): T {\r\n    return p;\r\n}\r\n\r\nvar v = f([x => x]);\r\n```\r\n\r\nType argument inference processes arguments in up to two stages. The first stage avoids contextually typing function expressions, and gives those function expressions a wildcard type (in the compiler called anyFunctionType). The second stage contextually types the functions, and infers the correct type. However, in both stages, we add inference candidates. Which means that in the first stage, we may add an inference candidate that contains the anyFunctionType. This \"poisons the pot\", and masks the good inference.\r\n\r\nThe solution leverages the final stage of type argument inference, namely the computation of the common supertype among the inference candidates. We'd like the candidate that contains the anyFunctionType *not* to win. The way to make something not win is to make it not a supertype of the better thing. So the way I've fixed this is by adding a new subtype rule:\r\n\r\nLet S be the source type and T be the target. If S has signatures and T is the anyFunctionType, then S is not a subtype of T. Note that it's still assignable, it's just not a subtype. This is sufficient to make the anyFunctionType not win over the real function type."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/123808840","html_url":"https://github.com/Microsoft/TypeScript/pull/3968#issuecomment-123808840","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/3968","id":123808840,"user":{"login":"JsonFreeman","id":8052525,"avatar_url":"https://avatars.githubusercontent.com/u/8052525?v=3","gravatar_id":"","url":"https://api.github.com/users/JsonFreeman","html_url":"https://github.com/JsonFreeman","followers_url":"https://api.github.com/users/JsonFreeman/followers","following_url":"https://api.github.com/users/JsonFreeman/following{/other_user}","gists_url":"https://api.github.com/users/JsonFreeman/gists{/gist_id}","starred_url":"https://api.github.com/users/JsonFreeman/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JsonFreeman/subscriptions","organizations_url":"https://api.github.com/users/JsonFreeman/orgs","repos_url":"https://api.github.com/users/JsonFreeman/repos","events_url":"https://api.github.com/users/JsonFreeman/events{/privacy}","received_events_url":"https://api.github.com/users/JsonFreeman/received_events","type":"User","site_admin":false},"created_at":"2015-07-22T17:57:20Z","updated_at":"2015-07-22T17:57:20Z","body":"I'll try bubbling up a flag to indicate that the type contains anyFunctionType, like we discussed."}}