René's URL Explorer Experiment


Title: Generic type arguments not inferred, default to {} · Issue #5884 · microsoft/TypeScript · GitHub

Open Graph Title: Generic type arguments not inferred, default to {} · Issue #5884 · microsoft/TypeScript

X Title: Generic type arguments not inferred, default to {} · Issue #5884 · microsoft/TypeScript

Description: I sometimes run into scenarios where it's clear to me what a generic type argument should be, but typescript fails to infer it. I think this is because inference only looks at the call site, and not the context. The example I just ran in...

Open Graph Description: I sometimes run into scenarios where it's clear to me what a generic type argument should be, but typescript fails to infer it. I think this is because inference only looks at the call site, and no...

X Description: I sometimes run into scenarios where it's clear to me what a generic type argument should be, but typescript fails to infer it. I think this is because inference only looks at the call site, an...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/5884

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic type arguments not inferred, default to {}","articleBody":"I sometimes run into scenarios where it's clear to me what a generic type argument should be, but typescript fails to infer it. I think this is because inference only looks at the call site, and not the context. The example I just ran into was this:\n\n``` typescript\nfunction comparing \u003cA,B> (f : (x : A) => B) : (x : A, y : A) => number {\n    return function (x : A, y : A) : number {\n        return f(x) \u003c f(y) ? -1 : x == y ? 0 : 1;\n    }\n}\n\nvar x : Array\u003c{ foo : string }> = [{ foo : \"hello\" }, { foo : \"world\"}];\n\n// Works, explicit types\nfunction getFoo (o : { foo : string }) : string { return o.foo }\nx.sort(comparing(getFoo))\n\n// Works, inferred any everywhere\nfunction getFoo2 (o) { return o.foo }\nx.sort(comparing(getFoo2))\n\n// Doesn't work, infers type parameters to {}\nx.sort(comparing(o => o.foo))\n```\n\nIn the last case it infers type parameter `A` to `{}`, causing it to fail since `{}` has no property `foo`. But from the context (`comparing` should return a function `(x : { foo : string }, y : { foo : string }) : number)` because it is used as an argument to `sort` on `x`) it should be clear that `A` should be `{ foo : string }`.\n\nIs there any way this kind of inference could be added, or is this too complicated due to overloads/subtyping/etc.\n\nP.S. There seem to be several issues about things like this, but they all seem slightly different. If they're not, my apologies. I'd like to have a place where I can track this issue, so I would appreciate any pointers to another ticket, a FAQ, etc.\n","author":{"url":"https://github.com/hesselink","@type":"Person","name":"hesselink"},"datePublished":"2015-12-02T11:36:17Z","url":"https://github.com/microsoft/TypeScript/issues/5884"}

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:9ab4b9c5-6bd1-793d-8bae-6ece30e6a338
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA93E:26ECEB:21C6145:2AEA217:6B0162DC
html-safe-nonce881b1bdd1a3bcac3629d3adbfea91013656ebf37adca12c5590c6315dbfa0e7b
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOTNFOjI2RUNFQjoyMUM2MTQ1OjJBRUEyMTc6NkIwMTYyREMiLCJ2aXNpdG9yX2lkIjoiODgwMzc4MDE2OTM1NDUzNTY0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac64434dda4ae4302d901f3ee7032af72f22e5fbc1d7194a5e2ed93fc34bbd7182
hovercard-subject-tagissue:119923536
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/5884/issue_layout
twitter:imagehttps://opengraph.githubassets.com/91e739c1b5ad8d46cbe82b3b71a46d12a263ca2e27c3a06011abb4006421cd47/microsoft/TypeScript/issues/5884
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/91e739c1b5ad8d46cbe82b3b71a46d12a263ca2e27c3a06011abb4006421cd47/microsoft/TypeScript/issues/5884
og:image:altI sometimes run into scenarios where it's clear to me what a generic type argument should be, but typescript fails to infer it. I think this is because inference only looks at the call site, and no...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamehesselink
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/5884#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F5884
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%2F5884
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/5884
Reloadhttps://github.com/microsoft/TypeScript/issues/5884
Reloadhttps://github.com/microsoft/TypeScript/issues/5884
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)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/5884
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/5884
Generic type arguments not inferred, default to {}https://github.com/microsoft/TypeScript/issues/5884#top
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
https://github.com/hesselink
Erik Hesselink (hesselink)https://github.com/hesselink
on Dec 2, 2015https://github.com/microsoft/TypeScript/issues/5884#issue-119923536
https://github.com/zpdDG4gta8XKpMCd
ZpdDG4gta (zpdDG4gta8XKpMCd)https://github.com/zpdDG4gta8XKpMCd
on Dec 2, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-161282555
https://github.com/hesselink
Erik Hesselink (hesselink)https://github.com/hesselink
on Dec 2, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-161283506
https://github.com/zpdDG4gta8XKpMCd
ZpdDG4gta (zpdDG4gta8XKpMCd)https://github.com/zpdDG4gta8XKpMCd
on Dec 2, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-161285343
http://stackoverflow.com/questions/7234095/why-is-scalas-type-inference-not-as-powerful-as-haskellshttp://stackoverflow.com/questions/7234095/why-is-scalas-type-inference-not-as-powerful-as-haskells
https://github.com/hesselink
Erik Hesselink (hesselink)https://github.com/hesselink
on Dec 2, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-161285942
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
on Dec 3, 2015https://github.com/microsoft/TypeScript/issues/5884#event-482056864
https://github.com/felixfbecker
Felix Becker (felixfbecker)https://github.com/felixfbecker
on Dec 21, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-166280039
https://github.com/weswigham
Wesley Wigham (weswigham)https://github.com/weswigham
on Dec 21, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-166297316
Felix Becker (@felixfbecker)https://github.com/felixfbecker
https://github.com/felixfbecker
Felix Becker (felixfbecker)https://github.com/felixfbecker
on Dec 21, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-166297965
Wesley Wigham (@weswigham)https://github.com/weswigham
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Dec 21, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-166384984
Felix Becker (@felixfbecker)https://github.com/felixfbecker
https://github.com/DanielRosenwasser
Daniel Rosenwasser (DanielRosenwasser)https://github.com/DanielRosenwasser
on Dec 28, 2015https://github.com/microsoft/TypeScript/issues/5884#issuecomment-167612291
#5254https://github.com/microsoft/TypeScript/issues/5254
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jan 7, 2016https://github.com/microsoft/TypeScript/issues/5884#issuecomment-169752510
#5254https://github.com/microsoft/TypeScript/issues/5254
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jan 7, 2016https://github.com/microsoft/TypeScript/issues/5884#event-508524312
Barney Stratford (BarneyStratford)https://github.com/BarneyStratford
on Jul 13, 2017https://github.com/microsoft/TypeScript/issues/5884#event-1162149239
Fix type error in PlayerIcon. The type system is not able to infer th…https://github.com/BarneyStratford/online-go.com/commit/7b7066752fa599cb1ab386914e611091cdc2b0d4
7b70667https://github.com/BarneyStratford/online-go.com/commit/7b7066752fa599cb1ab386914e611091cdc2b0d4
microsofthttps://github.com/microsoft
on Jun 19, 2018https://github.com/microsoft/TypeScript/issues/5884#event-1689626569
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/5884
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/5884
QuestionAn issue which isn't directly actionable in codehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Question%22
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.