{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/943","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/943/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/943/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/943/events","html_url":"https://github.com/Microsoft/TypeScript/issues/943","id":46547257,"number":943,"title":"Use different relation when checking overload vs implementation signature compatibility","user":{"login":"RyanCavanaugh","id":6685088,"avatar_url":"https://avatars.githubusercontent.com/u/6685088?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanCavanaugh","html_url":"https://github.com/RyanCavanaugh","followers_url":"https://api.github.com/users/RyanCavanaugh/followers","following_url":"https://api.github.com/users/RyanCavanaugh/following{/other_user}","gists_url":"https://api.github.com/users/RyanCavanaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanCavanaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanCavanaugh/subscriptions","organizations_url":"https://api.github.com/users/RyanCavanaugh/orgs","repos_url":"https://api.github.com/users/RyanCavanaugh/repos","events_url":"https://api.github.com/users/RyanCavanaugh/events{/privacy}","received_events_url":"https://api.github.com/users/RyanCavanaugh/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Needs%20Proposal","name":"Needs Proposal","color":"556b75"},{"url":"https://api.github.com/repos/Microsoft/TypeScript/labels/Suggestion","name":"Suggestion","color":"006b75"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2014-10-22T19:02:54Z","updated_at":"2015-04-27T21:21:08Z","closed_at":null,"body":"Consider some code:\r\n\r\n```ts\r\n/* ... disjoint classes Giraffe, Elephant which extend Animal ... */\r\nfunction f(n: string): Giraffe;\r\nfunction f(n: number): Elephant;\r\nfunction f(n: any): Animal {\r\n  if(typeof n === 'string') {\r\n    return new Giraffe(n);\r\n  } else if(typeof n === 'number') {\r\n    return new Elephant(n);\r\n  }\r\n}\r\n```\r\n\r\nPerhaps surprisingly, this yields errors on the overload signatures because the function implementation signature is not assignable *to* the overload signatures. This is unfortunate for implementors as they must use `:any` when implementing a function with disjoint parameter types in its overloads. Now that union types are possible, the implementor of `f` could even write `Giraffe|Elephant` to get more specific type checking of their return expressions.\r\n\r\nOne option is to change the relation in 6.1 from \"assignable to\" to \"assignable to or from\". This solves the issue above, but has a negative side effect of allowing an implementation signature to have more required parameters than any of the overloads. This might be a desirable trade-off compared to not allowing implementations to have good return expression checking. Alternatively, we could create some new kind of relation that is bivariant for return types but maintains the existing requirements of parameter arity.\r\n\r\nNote that we do want to use the opposite assignability relation here as the implementation signature may be of an inconsequentially more-specific type."},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/96825871","html_url":"https://github.com/Microsoft/TypeScript/issues/943#issuecomment-96825871","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/943","id":96825871,"user":{"login":"RyanCavanaugh","id":6685088,"avatar_url":"https://avatars.githubusercontent.com/u/6685088?v=3","gravatar_id":"","url":"https://api.github.com/users/RyanCavanaugh","html_url":"https://github.com/RyanCavanaugh","followers_url":"https://api.github.com/users/RyanCavanaugh/followers","following_url":"https://api.github.com/users/RyanCavanaugh/following{/other_user}","gists_url":"https://api.github.com/users/RyanCavanaugh/gists{/gist_id}","starred_url":"https://api.github.com/users/RyanCavanaugh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RyanCavanaugh/subscriptions","organizations_url":"https://api.github.com/users/RyanCavanaugh/orgs","repos_url":"https://api.github.com/users/RyanCavanaugh/repos","events_url":"https://api.github.com/users/RyanCavanaugh/events{/privacy}","received_events_url":"https://api.github.com/users/RyanCavanaugh/received_events","type":"User","site_admin":false},"created_at":"2015-04-27T21:21:08Z","updated_at":"2015-04-27T21:21:08Z","body":"Come up with some reasonable behavior specification"}}