Title: Don't widen return types of function expressions · Issue #241 · microsoft/TypeScript · GitHub
Open Graph Title: Don't widen return types of function expressions · Issue #241 · microsoft/TypeScript
X Title: Don't widen return types of function expressions · Issue #241 · microsoft/TypeScript
Description: This change courtesy Jason Freeman (@JsonFreeman) who is trying it out (context elided: widening of function expression return types) The problem with this widening is observable in type argument inference and no implicit any. For type a...
Open Graph Description: This change courtesy Jason Freeman (@JsonFreeman) who is trying it out (context elided: widening of function expression return types) The problem with this widening is observable in type argument i...
X Description: This change courtesy Jason Freeman (@JsonFreeman) who is trying it out (context elided: widening of function expression return types) The problem with this widening is observable in type argument i...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/241
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Don't widen return types of function expressions","articleBody":"This change courtesy @JsonFreeman who is trying it out\n\n(context elided: widening of function expression return types)\n\nThe problem with this widening is observable in type argument inference and no implicit any. For type argument inference, we are prone to infer an any, where we should not:\n\n``` ts\nfunction f\u003cT>(x: T, y: T): T { }\nf(1, null); // returns number\nf(() => 1, () => null); // returns () => any, but should return () => number\n```\n\nSo after we get to parity, I propose we do the following. We do not widen function expressions. A function is simply given a function type. However, a function declaration (and a named function expression) introduces a name whose type is the widened form of the type of the function. Very simple to explain and simple to implement.\n\nI’ve been told that this would be a breaking change, because types that used to be any are now more specific types. But here are some reasons why it would be okay:\n- In the places where you actually need the type to be any (because there are no other inference candidates), you would still get any as a result\n- In places where there was a better (more specific) type to infer, you’d get the better type. \n- With the noImplicitAny flag, you’d get fewer errors because there are actually fewer implicit anys\n### Questions:\n\n> Is a principle of design changes going forward to not switch from 'any' to a more precise type because it can be a breaking change?\n\nGoing with 'not a breaking change' here because this is unlikely to break working code, but we need to verify this.\n\n> Would this manufacture two types? \n\nIn essence, we already have two types: The original and the widened type. So by that measure this is not really a change\n\n> Has someone tried it?\n\nJason willing to try it out and report back\n","author":{"url":"https://github.com/RyanCavanaugh","@type":"Person","name":"RyanCavanaugh"},"datePublished":"2014-07-24T20:40:03Z","url":"https://github.com/microsoft/TypeScript/issues/241"}
| 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:5990f0ce-b1e1-fa01-73bd-c3b5f9f1d1fa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D440:683FF:35B69F:470D20:6B00C46A |
| html-safe-nonce | db009ea12688471e55e78a0aed515f9c9606e55f3631fc8600be443684a941bc |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDQwOjY4M0ZGOjM1QjY5Rjo0NzBEMjA6NkIwMEM0NkEiLCJ2aXNpdG9yX2lkIjoiMzcxMDczMTQzOTIxMDI4NDEzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 3023e8c2021b39e481426c0f6b78cb0733d9b0ae8609ffe0d4ba1eafd9ff9f9f |
| hovercard-subject-tag | issue:38671659 |
| 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/241/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bd238d4ca6cfa6c349258e1265cbfa87025bb069832985e7649aef62d0895ad1/microsoft/TypeScript/issues/241 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bd238d4ca6cfa6c349258e1265cbfa87025bb069832985e7649aef62d0895ad1/microsoft/TypeScript/issues/241 |
| og:image:alt | This change courtesy Jason Freeman (@JsonFreeman) who is trying it out (context elided: widening of function expression return types) The problem with this widening is observable in type argument i... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RyanCavanaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 93edd3bebc4afb7ce711ee74cb5d2a95927850b082a4d43e212222389cb1c415 |
| 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 | 1fee81a280ea86312b69448e261b418189bfd5b5 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width