Title: Type parameters do not get fixed when the compiler visits the same signature multiple times · Issue #2378 · microsoft/TypeScript · GitHub
Open Graph Title: Type parameters do not get fixed when the compiler visits the same signature multiple times · Issue #2378 · microsoft/TypeScript
X Title: Type parameters do not get fixed when the compiler visits the same signature multiple times · Issue #2378 · microsoft/TypeScript
Description: As of change #2356, the following code gives the correct result in the batch compiler: declare function f
Open Graph Description: As of change #2356, the following code gives the correct result in the batch compiler: declare function f
X Description: As of change #2356, the following code gives the correct result in the batch compiler: declare function f<T>(x: T, y: (p: T) => T, z: (p: T) => T): T; f(0, x => null, x => x.blahb...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/2378
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type parameters do not get fixed when the compiler visits the same signature multiple times","articleBody":"As of change #2356, the following code gives the correct result in the batch compiler:\n\n``` ts\ndeclare function f\u003cT>(x: T, y: (p: T) => T, z: (p: T) => T): T;\nf(0, x => null, x => x.blahblah);\n```\n\nNamely, we infer T to be number, and we get an error on blahblah.\n\nHowever, there are a few things still wrong:\n- The language service does not show the correct result. It shows both x's to be number, but if you hover on f, you will see that it was instantiated to `any`, instead of `number`.\n- If you add another overload, the wrong type argument gets inferred:\n\n``` ts\ndeclare function f\u003cT>(x: T, y: (p: T) => T, z: (p: T) => T): T;\ndeclare function f();\nf(0, x => null, x => x.blahblah);\n```\n\nNow suddenly blahblah is not an error, and the second x is `any`.\n- In theory, if this overload is not assignable, but it has already fixed the type parameter T, and another overload comes along with a type parameter in the same position, that second type parameter will not get fixed. I don't have a good repro for this, but it is certainly a possibility in theory.\n\nAll of these issues happen because when a function expression parameter causes a type parameter to get fixed, it only does so if it is affected by the type of that type parameter. I believe the right thing here is that if a function parameter aligns with the type parameter, it should still fix it, even if it has already been assigned a type in the past. That way, it will fix the type parameter no matter which signature is being visited, or whether this signature has been visited before.\n\nI consider this bug a followup to bugs #2127 and #2182.\n","author":{"url":"https://github.com/JsonFreeman","@type":"Person","name":"JsonFreeman"},"datePublished":"2015-03-16T23:01:09Z","url":"https://github.com/microsoft/TypeScript/issues/2378"}
| 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:a16ee425-1c32-a1cb-a7b2-c81798b150d2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CAD4:17FB7:7CEB1:9C87C:6B00F545 |
| html-safe-nonce | 194c3a24ad511d03339b114e7fd18ec281a57f69e51296a00bfd729650ac2697 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQUQ0OjE3RkI3OjdDRUIxOjlDODdDOjZCMDBGNTQ1IiwidmlzaXRvcl9pZCI6IjQ2ODMxNzk0OTYwNzYwMTQ5MTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | d18912bf0cb48c0c3864e19a12becfa6d2e3698b3acd2371f8f182c297bcf0de |
| hovercard-subject-tag | issue:62231305 |
| 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/2378/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb2718aa9fba0dbda4bcfa3777a9b86d1e63806bc14e4ad4c56fbed5fc468b22/microsoft/TypeScript/issues/2378 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb2718aa9fba0dbda4bcfa3777a9b86d1e63806bc14e4ad4c56fbed5fc468b22/microsoft/TypeScript/issues/2378 |
| og:image:alt | As of change #2356, the following code gives the correct result in the batch compiler: declare function f |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JsonFreeman |
| 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