René's URL Explorer Experiment


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

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@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-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:5990f0ce-b1e1-fa01-73bd-c3b5f9f1d1fa
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD440:683FF:35B69F:470D20:6B00C46A
html-safe-noncedb009ea12688471e55e78a0aed515f9c9606e55f3631fc8600be443684a941bc
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJENDQwOjY4M0ZGOjM1QjY5Rjo0NzBEMjA6NkIwMEM0NkEiLCJ2aXNpdG9yX2lkIjoiMzcxMDczMTQzOTIxMDI4NDEzOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac3023e8c2021b39e481426c0f6b78cb0733d9b0ae8609ffe0d4ba1eafd9ff9f9f
hovercard-subject-tagissue:38671659
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/241/issue_layout
twitter:imagehttps://opengraph.githubassets.com/bd238d4ca6cfa6c349258e1265cbfa87025bb069832985e7649aef62d0895ad1/microsoft/TypeScript/issues/241
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/bd238d4ca6cfa6c349258e1265cbfa87025bb069832985e7649aef62d0895ad1/microsoft/TypeScript/issues/241
og:image:altThis 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:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameRyanCavanaugh
hostnamegithub.com
expected-hostnamegithub.com
None93edd3bebc4afb7ce711ee74cb5d2a95927850b082a4d43e212222389cb1c415
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release1fee81a280ea86312b69448e261b418189bfd5b5
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/241#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F241
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F241
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/241
Reloadhttps://github.com/microsoft/TypeScript/issues/241
Reloadhttps://github.com/microsoft/TypeScript/issues/241
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests307 (307)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/241
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/241
Don't widen return types of function expressionshttps://github.com/microsoft/TypeScript/issues/241#top
Experimentation NeededSomeone needs to try this out to see what happenshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Experimentation%20Needed%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
Backloghttps://github.com/microsoft/TypeScript/milestone/29
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jul 24, 2014https://github.com/microsoft/TypeScript/issues/241#issue-38671659
Jason Freeman (@JsonFreeman)https://github.com/JsonFreeman
Nexthttps://github.com/microsoft/TypeScript/issues/241?timeline_page=1
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Suggestionhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Jul 24, 2014https://github.com/microsoft/TypeScript/issues/241#event-145331580
Jason Freeman (JsonFreeman)https://github.com/JsonFreeman
on Jul 24, 2014https://github.com/microsoft/TypeScript/issues/241#event-145337387
Jason Freeman (JsonFreeman)https://github.com/JsonFreeman
on Oct 13, 2014https://github.com/microsoft/TypeScript/issues/241#event-177825008
Correct contextual typing with union typeshttps://github.com/microsoft/TypeScript/commit/83d9aed005502523ac3ef7198d92c51c8f2bb211
83d9aedhttps://github.com/microsoft/TypeScript/commit/83d9aed005502523ac3ef7198d92c51c8f2bb211
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Mar 19, 2015https://github.com/microsoft/TypeScript/issues/241#issuecomment-83238338
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
Needs ProposalThis issue needs a plan that clarifies the finer details of how it could be implemented.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Proposal%22
Needs More InfoThe issue still hasn't been fully clarifiedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20More%20Info%22
on Jul 27, 2015https://github.com/microsoft/TypeScript/issues/241#event-366532390
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jul 27, 2015https://github.com/microsoft/TypeScript/issues/241#issuecomment-125341150
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
Jason Freeman (JsonFreeman)https://github.com/JsonFreeman
on Jul 27, 2015https://github.com/microsoft/TypeScript/issues/241#event-366532962
https://github.com/JsonFreeman
Jason Freeman (JsonFreeman)https://github.com/JsonFreeman
on Mar 22, 2016https://github.com/microsoft/TypeScript/issues/241#issuecomment-199633475
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Mar 22, 2016https://github.com/microsoft/TypeScript/issues/241#event-598191475
https://github.com/myitcv
Paul Jolly (myitcv)https://github.com/myitcv
on Apr 8, 2016https://github.com/microsoft/TypeScript/issues/241#issuecomment-207529054
#7220https://github.com/microsoft/TypeScript/issues/7220
playgroundhttp://www.typescriptlang.org/play/index.html#src=interface%20G%3CK%2C%20R%3E%20%7B%0A%09%28v%3A%20K%29%3A%20R%3B%0A%7D%0A%0Afunction%20F%3CT%3E%28v%3A%20T%29%3A%20T%20%7B%0A%20%20%20%20return%20v%3B%0A%7D%0A%0Ainterface%20A%20%7B%0A%09__Type%3A%20%22A%22%3B%0A%7D%0A%0Ainterface%20B%20%7B%0A%09__Type%3A%20%22B%22%3B%0A%7D%0A%0Alet%20a%3A%20A%3B%0Alet%20b%3A%20B%3B%0A%0Aa%20%3D%20b%3B%20%2F%2F%20OK%3A%20error%20as%20expected%2C%20B%20is%20not%20assignable%20to%20A%0Ab%20%3D%20a%3B%20%2F%2F%20OK%3A%20error%20as%20expected%2C%20A%20is%20not%20assignable%20to%20B%0A%0Alet%20x%3A%20G%3CA%2C%20B%3E%20%3D%20F%3B%20%20%2F%2F%20How%20is%20this%20possible%3F
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Apr 8, 2016https://github.com/microsoft/TypeScript/issues/241#issuecomment-207554740
https://github.com/JsonFreeman
Jason Freeman (JsonFreeman)https://github.com/JsonFreeman
on Apr 8, 2016https://github.com/microsoft/TypeScript/issues/241#issuecomment-207559139
Paul Jolly (@myitcv)https://github.com/myitcv
#138https://github.com/microsoft/TypeScript/issues/138
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
on Aug 15, 2017https://github.com/microsoft/TypeScript/issues/241#event-1206890033
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Sep 2, 2020https://github.com/microsoft/TypeScript/issues/241#issuecomment-685860134
#40311https://github.com/microsoft/TypeScript/pull/40311
#40311 (comment)https://github.com/microsoft/TypeScript/pull/40311#issuecomment-683255340
https://github.com/mrlubos
Lubos (mrlubos)https://github.com/mrlubos
on May 17, 2021https://github.com/microsoft/TypeScript/issues/241#issuecomment-842054907
Daniel Rosenwasser (@DanielRosenwasser)https://github.com/DanielRosenwasser
https://github.com/jdanielson-indeed
jdanielson-indeedhttps://github.com/jdanielson-indeed
on Sep 14, 2021https://github.com/microsoft/TypeScript/issues/241#issuecomment-919407359
https://github.com/EddyVinck
Eddy (EddyVinck)https://github.com/EddyVinck
on May 16, 2022https://github.com/microsoft/TypeScript/issues/241#issuecomment-1127373318
https://github.com/folex
Alexey Pyshnenko (folex)https://github.com/folex
on May 19, 2022https://github.com/microsoft/TypeScript/issues/241#issuecomment-1131809447
https://github.com/MaksimKlepikov
Maksim Klepikov (MaksimKlepikov)https://github.com/MaksimKlepikov
on May 30, 2022https://github.com/microsoft/TypeScript/issues/241#issuecomment-1140884724
peizhe.chen (pezy)https://github.com/pezy
on Oct 25, 2023https://github.com/microsoft/TypeScript/issues/241#event-10766140340
Add lint rule to prefer `map((): T => {})` over `map(() => {})` (#…https://github.com/pezy/studio/commit/e7d36f3a6487f853cd74fcafd7e5454f13bd274e
e7d36f3https://github.com/pezy/studio/commit/e7d36f3a6487f853cd74fcafd7e5454f13bd274e
https://github.com/Akryum
Guillaume Chau (Akryum)https://github.com/Akryum
on Oct 26, 2023https://github.com/microsoft/TypeScript/issues/241#issuecomment-1781382483
Playgroundhttps://www.typescriptlang.org/play#code/JYOwLgpgTgZghgYwgAgEoQM4HsA2A3aDZAbwChlkBFAV2gE8AuE8i5bAWwgDFgIcATJgAoAlMgC8APmatWUCAEdqwefx59BbMFFABzFrKwAHMMCwg4OdQIDqwMAAsAKnSNYA-Ewza9B5AF8WQMDSBHNvZHlsfEImdGiCKCJxGSpaKEZUig5uXgFhMSlkITJZCnklFQg1PM0AchzkPEtaOoAaPwoAei7kAAEwDABaCAAPIwgEMBGoKCwoTuRjU3NLa347RxcjNyYGrE4mloh2v38RINJAoA
Other examplehttps://www.typescriptlang.org/play#code/JYOwLgpgTgZghgYwgAgPIAczAPYgM7IDeAUMsjNtgFzJ5hSgDmpyARnFAPw0gCuAtq2jEAvsWIxeIBFly0IYXumQAKGCBoqAlMgC8APjSYc+HSVHjieBUpXa9hkmSg2oIIizIVqyAOQAWACZfABpPZAB6COQAATA8AFoIAA90CBkkqChsKGQQXCTk4DoIcGR0bPRw9gAvGiDI6IAeBOQwAE90bBYxES1xSWlZd2tFdEDVbEw8GgxhvDNxMSsbcZUnckoaAOCwslr6iajkFrbO7r6BqRkTZH4IAHdsVS1Z41wCDZdFNw8yLy2fiCoWqcDqyAax1OHS6PQsEmuw3kYwAzKp1JpRnMTDNJtM3vMdAZkAA3bDAAAmRMMZMpi3hoyUKLsWPepgcf2R2I+63C3m2wL2-wOEKOzVaMO6ZEulyAA
https://github.com/yamcodes
Yam Borodetsky (yamcodes)https://github.com/yamcodes
on Aug 23, 2024https://github.com/microsoft/TypeScript/issues/241#issuecomment-2307518157
https://github.com/ernestostifano
Ernesto Stifano (ernestostifano)https://github.com/ernestostifano
on Sep 21, 2024https://github.com/microsoft/TypeScript/issues/241#issuecomment-2365177697
Yam Borodetsky (@yamcodes)https://github.com/yamcodes
https://github.com/alvis
Alvis Tang (alvis)https://github.com/alvis
on Oct 6, 2024https://github.com/microsoft/TypeScript/issues/241#issuecomment-2395429477
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
Daniel Rosenwasser (@DanielRosenwasser)https://github.com/DanielRosenwasser
https://github.com/snarbies
snarbieshttps://github.com/snarbies
on Oct 7, 2024https://github.com/microsoft/TypeScript/issues/241#issuecomment-2396897225
Dmitry Dyachkov (e965)https://github.com/e965
Incorrect type checking (maybe?) for recursive types #61520https://github.com/microsoft/TypeScript/issues/61520
on Apr 2, 2025https://github.com/microsoft/TypeScript/issues/241#event-17097899311
Jake Bailey (jakebailey)https://github.com/jakebailey
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
on Aug 20, 2026https://github.com/microsoft/TypeScript/issues/241#event-29770223586
Hauke Schnau (HaukeSchnau)https://github.com/HaukeSchnau
on Oct 24, 2026https://github.com/microsoft/TypeScript/issues/241#event-34127295784
feat: check every definition and type pkgs by namehttps://github.com/HaukeSchnau/typeflake/commit/cfa40b852a233b16e87995e373662a6c829f5af1
cfa40b8https://github.com/HaukeSchnau/typeflake/commit/cfa40b852a233b16e87995e373662a6c829f5af1
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/241
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/241
Experimentation NeededSomeone needs to try this out to see what happenshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Experimentation%20Needed%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
BacklogNo due datehttps://github.com/microsoft/TypeScript/milestone/29
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.