{"action":"created","issue":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17295","repository_url":"https://api.github.com/repos/Microsoft/TypeScript","labels_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17295/labels{/name}","comments_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17295/comments","events_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17295/events","html_url":"https://github.com/Microsoft/TypeScript/issues/17295","id":244044683,"number":17295,"title":"Overload type checking bug in JSX","user":{"login":"alshain","id":349397,"avatar_url":"https://avatars2.githubusercontent.com/u/349397?v=4","gravatar_id":"","url":"https://api.github.com/users/alshain","html_url":"https://github.com/alshain","followers_url":"https://api.github.com/users/alshain/followers","following_url":"https://api.github.com/users/alshain/following{/other_user}","gists_url":"https://api.github.com/users/alshain/gists{/gist_id}","starred_url":"https://api.github.com/users/alshain/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alshain/subscriptions","organizations_url":"https://api.github.com/users/alshain/orgs","repos_url":"https://api.github.com/users/alshain/repos","events_url":"https://api.github.com/users/alshain/events{/privacy}","received_events_url":"https://api.github.com/users/alshain/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-07-19T13:40:44Z","updated_at":"2017-08-28T21:58:36Z","closed_at":null,"body":"<!-- BUGS: Please use this template. -->\r\n<!-- QUESTIONS: This is not a general support forum! Ask Qs at http://stackoverflow.com/questions/tagged/typescript -->\r\n<!-- SUGGESTIONS: See https://github.com/Microsoft/TypeScript-wiki/blob/master/Writing-Good-Design-Proposals.md -->\r\n\r\n**TypeScript Version:**  2.4.1\r\n\r\n**Code**\r\nUnfortunately, I haven't yet been able to create a small reproducible example. Of course, I can't post the entire company project here in order to reproduce the bug.\r\n\r\nInstead, I'm going to sketch out my code and my reasoning to explain, why I think there is a bug lurking somewhere, also to gather advice on how I could create an example to reproduce it in a small self-contained example.\r\n\r\n```ts\r\n1. export function ReferenceField<V, T, R>(props: StringReferenceFieldProps<string, T, R>): JSX.Element;\r\n2. export function ReferenceField<V, T, R>(props: ReferenceFieldPropsWithRest<V, T, R>): JSX.Element;\r\n3. export function ReferenceField<V, T, R>(props: ReferenceFieldProps<V, T, R>) {\r\n```\r\n\r\nThe general idea is, that I've got React type-safe react components. In (2), an additional parameter property `parse` is expected of type `(v: V) => string`. So if you provide some component with string storage, it doesn't need to parse and won't demand a parser. Otherwise, it will demand a parser.\r\n\r\n```ts\r\n\r\nI call it with props where `V` is (would be) inferred to be `number` and I provide a  `(number) => string` parser.\r\n\r\n```\r\n**Expected behavior:**\r\n\r\n* I expect my code to type check.\r\n* If it doesn't I expect TypeScript to tell me which overload failed.\r\n\r\nFrom my experiments, it seems that if the first overload signature doesn't match, it will try the second, until the last (2), and report errors *only* with respect to the last. It might be better to output an error message for each mis-match instead.\r\n\r\n\r\n**Actual behavior:**\r\n\r\nI get an error message:\r\n\r\n```\r\n(313,49): error TS2322: Type '{ for: MappedDataType<number, SourceDataType>; parser: (s: string) => { v: undefined; error: boolean...' is not assignable to type 'IntrinsicAttributes & ReferenceFieldPropsWithRest<number, SourceDataType, FetchResult>'.\r\n  Type '{ for: MappedDataType<number, SourceDataType>; parser: (s: string) => { v: undefined; error: boolean...' is not assignable to type 'ReferenceFieldPropsWithRest<number, SourceDataType, FetchResult>'.\r\n    Types of property 'onChangeField' are incompatible.\r\n      Type '(v: number, field: MappedDataType<string, SourceDataType>, oldV: string | undefined) => void' is not assignable to type 'FieldChangeEventHandler<number, SourceDataType> | undefined'.\r\n        Type '(v: number, field: MappedDataType<string, SourceDataType>, oldV: string | undefined) => void' is not assignable to type 'FieldChangeEventHandler<number, SourceDataType>'.\r\n          Types of parameters 'field' and 'field' are incompatible.\r\n            Type 'MappedDataType<number, SourceDataType>' is not assignable to type 'MappedDataType<string, SourceDataType>'.\r\n              Type 'number' is not assignable to type 'string'.\r\n\r\n\r\n```\r\n\r\nCommenting line (1) type checking works just fine. How can this be? Shouldn't choose the overload (2) in the case where (1) is not commented?\r\n\r\nInvestigating further, if I change the `string` type parameter in (1) to something else, it will reflect this in the error message. Important is, that neither in (2) nor in my calling code does `string` appear anywhere. Why then does the first overload influence the error message?\r\n\r\nEven more interestingly, if I comment (2), the code must not compile. It doesn't, however, I get a completely different error message.\r\n\r\nThis suggests that TS does not fail my code against (1) if both are un-commented.\r\n\r\nAlso, swapping (1) and (2) makes the code compile. However, this is pointless since then the more general version comes first which leads to unhelpful error messages. (i.e. forget to provide a `parser`, and you're told to pass in stuff of type `string`, not that `parser` is missing)\r\n\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/Microsoft/TypeScript/issues/comments/325495516","html_url":"https://github.com/Microsoft/TypeScript/issues/17295#issuecomment-325495516","issue_url":"https://api.github.com/repos/Microsoft/TypeScript/issues/17295","id":325495516,"user":{"login":"mhegazy","id":8000722,"avatar_url":"https://avatars3.githubusercontent.com/u/8000722?v=4","gravatar_id":"","url":"https://api.github.com/users/mhegazy","html_url":"https://github.com/mhegazy","followers_url":"https://api.github.com/users/mhegazy/followers","following_url":"https://api.github.com/users/mhegazy/following{/other_user}","gists_url":"https://api.github.com/users/mhegazy/gists{/gist_id}","starred_url":"https://api.github.com/users/mhegazy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhegazy/subscriptions","organizations_url":"https://api.github.com/users/mhegazy/orgs","repos_url":"https://api.github.com/users/mhegazy/repos","events_url":"https://api.github.com/users/mhegazy/events{/privacy}","received_events_url":"https://api.github.com/users/mhegazy/received_events","type":"User","site_admin":false},"created_at":"2017-08-28T21:58:36Z","updated_at":"2017-08-28T21:58:36Z","body":"I will need some more context to be able to comment. "}}
{"actor":{"display_login":"mhegazy"}}