Title: Differing results for inference produced when identical overload count changes · Issue #21733 · microsoft/TypeScript · GitHub
Open Graph Title: Differing results for inference produced when identical overload count changes · Issue #21733 · microsoft/TypeScript
X Title: Differing results for inference produced when identical overload count changes · Issue #21733 · microsoft/TypeScript
Description: I happened to notice this while looking at something else inference related a bit ago. We already have a test that is looking for checking this, fixingTypeParametersRepeatedly3.ts, added in #2356, but it was accepted in #16368 (strict ge...
Open Graph Description: I happened to notice this while looking at something else inference related a bit ago. We already have a test that is looking for checking this, fixingTypeParametersRepeatedly3.ts, added in #2356, ...
X Description: I happened to notice this while looking at something else inference related a bit ago. We already have a test that is looking for checking this, fixingTypeParametersRepeatedly3.ts, added in #2356, ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/21733
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Differing results for inference produced when identical overload count changes","articleBody":"I happened to notice this while looking at something else inference related a bit ago. We already have a test that is looking for checking this, `fixingTypeParametersRepeatedly3.ts`, added in #2356, but it was accepted in #16368 (strict generic checks) with a (tiny, unnoticeable in all the other changes) baseline showing the fault.\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface Base {\r\n baseProp;\r\n}\r\ninterface Derived extends Base {\r\n toBase?(): Base;\r\n}\r\n\r\nvar derived: Derived;\r\n\r\ndeclare function foo\u003cT>(x: T, func: (p: T) => T): T;\r\nvar result = foo(derived, d => d.toBase());\r\n\r\n// bar should type check just like foo.\r\n// result2 should have the same type as result\r\ndeclare function bar\u003cT>(x: T, func: (p: T) => T): T;\r\ndeclare function bar\u003cT>(x: T, func: (p: T) => T): T;\r\nvar result2 = bar(derived, d => d.toBase());\r\n```\r\n\r\n**Expected behavior:**\r\n`result` and `result2` are assigned the same type (there's a comment in the test asserting as much) - they are implemented identically except `bar` has an extra identical overload. (note: this can happen easily in the real world nowadays via intersection types! Intersecting multiple interfaces with similar base interfaces can cause exactly this situation.)\r\n\r\n**Actual behavior:**\r\n`result` typechecks as `Derived`\r\n`result2` typechecks as `Base` (seems wrong, since `Base` definitely doesn't have the `toBase` method used in the callback!)\r\n\r\n`Derived` and `Base` are assignable to one another here, since `toBase` is optional, which is why the inference can succeed at all; however, `Base`, as reported in the second case can't actually have been the type used to typecheck the lambda body, as the `toBase` call doesn't cause an error in the test - I think the likely reason for the change in behavior is [this removal](https://github.com/Microsoft/TypeScript/pull/16368/files#diff-c3ed224e4daa84352f7f1abcd23e8ccaL16428), based on the content of the removed comment.\r\n","author":{"url":"https://github.com/weswigham","@type":"Person","name":"weswigham"},"datePublished":"2018-02-07T19:41:27Z","url":"https://github.com/microsoft/TypeScript/issues/21733"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f903bfa2-df11-3ca6-a32e-06373866b141 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D5C0:364B55:C0FE0E:FA8F2D:6B00ECBB |
| html-safe-nonce | 63b2822a3a3f291062291139a71f915069d5c9c8ea00ba3a7332f79492421362 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENUMwOjM2NEI1NTpDMEZFMEU6RkE4RjJEOjZCMDBFQ0JCIiwidmlzaXRvcl9pZCI6IjQyMjk2NTc3MTE1NTk2MzQxMDciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 44418e28cee6ac640bab573ebef8a1446168938a14a6dfa868a731727eedc0ef |
| hovercard-subject-tag | issue:295267057 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/21733/issue_layout |
| twitter:image | https://opengraph.githubassets.com/25029a25cecdafcd31e97cd65ee2771a5b46fb965ad2625490a9c1c98caab8d4/microsoft/TypeScript/issues/21733 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/25029a25cecdafcd31e97cd65ee2771a5b46fb965ad2625490a9c1c98caab8d4/microsoft/TypeScript/issues/21733 |
| og:image:alt | I happened to notice this while looking at something else inference related a bit ago. We already have a test that is looking for checking this, fixingTypeParametersRepeatedly3.ts, added in #2356, ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | weswigham |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4ef498cbabcbe3c50befc7a5b743e7072ee770b4daf0e15e54801180d1fa91fc |
| turbo-cache-control | no-preview |
| go-import | github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git |
| octolytics-dimension-user_id | 6154722 |
| octolytics-dimension-user_login | microsoft |
| octolytics-dimension-repository_id | 20929025 |
| octolytics-dimension-repository_nwo | microsoft/TypeScript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 20929025 |
| octolytics-dimension-repository_network_root_nwo | microsoft/TypeScript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9983dd5da06943f833c971dd5b6bc988e2858be5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width