Title: Type parameters do not get fixed when the compiler visits the same signature multiple times · Issue #2377 · microsoft/TypeScript · GitHub
Open Graph Title: Type parameters do not get fixed when the compiler visits the same signature multiple times · Issue #2377 · microsoft/TypeScript
X Title: Type parameters do not get fixed when the compiler visits the same signature multiple times · Issue #2377 · 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/2377
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 even if a function parameter does not align with the type parameter, it should still fix it. 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-16T22:56:21Z","url":"https://github.com/microsoft/TypeScript/issues/2377"}
| 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:c6b18add-b3ab-c73a-12da-d21897eef75c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E700:2679E9:1BAC5A3:24DF21F:6B01638C |
| html-safe-nonce | 4472218ece3d5ce10bdbd10b2155390b8e383e20b823fa76fcb308a33d377736 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFNzAwOjI2NzlFOToxQkFDNUEzOjI0REYyMUY6NkIwMTYzOEMiLCJ2aXNpdG9yX2lkIjoiNDMzMTI3NDQ4MTcwOTQ0MTkzMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2c72927c46caf6e4f02b54a9c729fd40c7e5dfea2b6e5edf6bf39df4c5e2dacf |
| hovercard-subject-tag | issue:62230277 |
| 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/2377/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb2718aa9fba0dbda4bcfa3777a9b86d1e63806bc14e4ad4c56fbed5fc468b22/microsoft/TypeScript/issues/2377 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb2718aa9fba0dbda4bcfa3777a9b86d1e63806bc14e4ad4c56fbed5fc468b22/microsoft/TypeScript/issues/2377 |
| 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 | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| 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 | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width