René's URL Explorer Experiment


Title: Infer return type of a function with provided argument types · Issue #26043 · microsoft/TypeScript · GitHub

Open Graph Title: Infer return type of a function with provided argument types · Issue #26043 · microsoft/TypeScript

X Title: Infer return type of a function with provided argument types · Issue #26043 · microsoft/TypeScript

Description: I'm trying to create something similar to native ReturnType type. In comparison to the later, it should also consider generic types of arguments. I guess the idea will be clear from the code below. If it can be done now - I'd be happy to...

Open Graph Description: I'm trying to create something similar to native ReturnType type. In comparison to the later, it should also consider generic types of arguments. I guess the idea will be clear from the code below....

X Description: I'm trying to create something similar to native ReturnType type. In comparison to the later, it should also consider generic types of arguments. I guess the idea will be clear from the code be...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Infer return type of a function with provided argument types","articleBody":"\u003c!-- 🚨 STOP 🚨 𝗦𝗧𝗢𝗣 🚨 𝑺𝑻𝑶𝑷 🚨\r\n\r\nHalf of all issues filed here are duplicates, answered in the FAQ, or not appropriate for the bug tracker. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\r\n\r\nPlease help us by doing the following steps before logging an issue:\r\n  * Search: https://github.com/Microsoft/TypeScript/search?type=Issues\r\n  * Read the FAQ: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\nI'm trying to create something similar to native ReturnType type. In comparison to the later, it should also consider generic types of arguments.\r\n\r\nI guess the idea will be clear from the code below.\r\n\r\nIf it can be done now - I'd be happy to receive some links. Otherways it'd be great to know if there are any plans to cover that behavior. In case it could be achieved by another not-implemented feature I'll be glad for the link to an issue to be able to track its progress. \r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:**  2.9.2\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** infer function return type\r\n\r\n**Code**\r\n\r\n```ts\r\n// it works with actual code:\r\nfunction identity\u003cT>(a: T) {\r\n    return a;\r\n}\r\n\r\nconst one = identity(1); // typeof one === 1 # everything is great\r\n\r\nfunction call\u003cA, R>(arg: A, fn: Func\u003cA, R>): R {\r\n    return fn(arg);\r\n}\r\n\r\nconst two = call(2 as 2, i => i) // typeof two === 2 # everything is great\r\n\r\n// but won't work with types\r\ntype Func\u003cA, R> = (arg: A) => R;\r\n// ReturnTypeByArg is inspired by `ReturnType` from TS 2.8.*\r\ntype ReturnTypeByArg\u003cT, F extends Func\u003cT, any>> = F extends Func\u003cT, infer R> ? R : any;\r\n\r\ntype Identity = \u003cT>(a: T) => T;\r\ntype Result = ReturnTypeByArg\u003c4, Identity>; // Result === {} # not what I expect\r\n```\r\n\r\n**Expected behavior:**\r\nI expect TS to be able to infer such return type\r\n\r\n**Actual behavior:**\r\nReturn type is `{}`\r\n\r\n**Playground Link:** [link](https://www.typescriptlang.org/play/#src=%0D%0Afunction%20identity%3CT%3E(a%3A%20T)%20%7B%0D%0A%20%20%20%20return%20a%3B%0D%0A%7D%0D%0A%0D%0Aconst%20one%20%3D%20identity(1)%3B%20%2F%2F%20typeof%20one%20%3D%3D%3D%201%20%23%20everything%20is%20great%0D%0A%0D%0Afunction%20call%3CA%2C%20R%3E(arg%3A%20A%2C%20fn%3A%20Func%3CA%2C%20R%3E)%3A%20R%20%7B%0D%0A%20%20%20%20return%20fn(arg)%3B%0D%0A%7D%0D%0A%0D%0Aconst%20two%20%3D%20call(2%20as%202%2C%20i%20%3D%3E%20i)%20%2F%2F%20typeof%20two%20%3D%3D%3D%202%20%23%20everything%20is%20great%0D%0A%0D%0Atype%20Func%3CA%2C%20R%3E%20%3D%20(arg%3A%20A)%20%3D%3E%20R%3B%0D%0Atype%20ReturnTypeByArg%3CT%2C%20F%20extends%20Func%3CT%2C%20any%3E%3E%20%3D%20F%20extends%20Func%3CT%2C%20infer%20R%3E%20%3F%20R%20%3A%20any%3B%0D%0A%0D%0Atype%20Identity%20%3D%20%3CT%3E(a%3A%20T)%20%3D%3E%20T%3B%0D%0Atype%20Result%20%3D%20ReturnTypeByArg%3C4%2C%20Identity%3E%3B%20%2F%2F%20Result%20%3D%3D%3D%20%7B%7D%20%23%20not%20what%20I%20expect)\r\n\r\n**Related Issues:** \u003c!-- Did you find other bugs that looked similar? -->\r\n","author":{"url":"https://github.com/int0h","@type":"Person","name":"int0h"},"datePublished":"2018-07-28T18:42:01Z","url":"https://github.com/microsoft/TypeScript/issues/26043"}

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:3be13b8e-d712-bee1-e691-f86b966c890a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAAC6:1CCECA:8C5CF5:BBAA6F:6B01BDCD
html-safe-nonce9b231c946da54210ab631a9eb59984bd12b62d842d044e1f8fb508d1a5b73b6d
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQUM2OjFDQ0VDQTo4QzVDRjU6QkJBQTZGOjZCMDFCRENEIiwidmlzaXRvcl9pZCI6IjcwNTgwMTMwMTkyMDk1NTg1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace59de0643e4468fea58a3e9b9de93c1cd04fcce9a58222f9544ee60ef7dcfbef
hovercard-subject-tagissue:345470038
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/26043/issue_layout
twitter:imagehttps://opengraph.githubassets.com/271f4e20359c526a686a7477052bde93397162df74dc02c4bc68c1a729f325e6/microsoft/TypeScript/issues/26043
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/271f4e20359c526a686a7477052bde93397162df74dc02c4bc68c1a729f325e6/microsoft/TypeScript/issues/26043
og:image:altI'm trying to create something similar to native ReturnType type. In comparison to the later, it should also consider generic types of arguments. I guess the idea will be clear from the code below....
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameint0h
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/26043#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F26043
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%2F26043
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/26043
Reloadhttps://github.com/microsoft/TypeScript/issues/26043
Reloadhttps://github.com/microsoft/TypeScript/issues/26043
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/26043
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/26043
Infer return type of a function with provided argument typeshttps://github.com/microsoft/TypeScript/issues/26043#top
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
https://github.com/int0h
int0hhttps://github.com/int0h
on Jul 28, 2018https://github.com/microsoft/TypeScript/issues/26043#issue-345470038
linkhttps://www.typescriptlang.org/play/#src=%0D%0Afunction%20identity%3CT%3E(a%3A%20T)%20%7B%0D%0A%20%20%20%20return%20a%3B%0D%0A%7D%0D%0A%0D%0Aconst%20one%20%3D%20identity(1)%3B%20%2F%2F%20typeof%20one%20%3D%3D%3D%201%20%23%20everything%20is%20great%0D%0A%0D%0Afunction%20call%3CA%2C%20R%3E(arg%3A%20A%2C%20fn%3A%20Func%3CA%2C%20R%3E)%3A%20R%20%7B%0D%0A%20%20%20%20return%20fn(arg)%3B%0D%0A%7D%0D%0A%0D%0Aconst%20two%20%3D%20call(2%20as%202%2C%20i%20%3D%3E%20i)%20%2F%2F%20typeof%20two%20%3D%3D%3D%202%20%23%20everything%20is%20great%0D%0A%0D%0Atype%20Func%3CA%2C%20R%3E%20%3D%20(arg%3A%20A)%20%3D%3E%20R%3B%0D%0Atype%20ReturnTypeByArg%3CT%2C%20F%20extends%20Func%3CT%2C%20any%3E%3E%20%3D%20F%20extends%20Func%3CT%2C%20infer%20R%3E%20%3F%20R%20%3A%20any%3B%0D%0A%0D%0Atype%20Identity%20%3D%20%3CT%3E(a%3A%20T)%20%3D%3E%20T%3B%0D%0Atype%20Result%20%3D%20ReturnTypeByArg%3C4%2C%20Identity%3E%3B%20%2F%2F%20Result%20%3D%3D%3D%20%7B%7D%20%23%20not%20what%20I%20expect
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jul 30, 2018https://github.com/microsoft/TypeScript/issues/26043#issuecomment-408931929
#6606https://github.com/microsoft/TypeScript/issues/6606
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
on Jul 30, 2018https://github.com/microsoft/TypeScript/issues/26043#event-1760677271
https://github.com/int0h
int0hhttps://github.com/int0h
on Jul 31, 2018https://github.com/microsoft/TypeScript/issues/26043#issuecomment-409213476
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
#6606https://github.com/microsoft/TypeScript/issues/6606
Trey Brisbane (@treybrisbane)https://github.com/treybrisbane
#6606https://github.com/microsoft/TypeScript/issues/6606
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Jul 31, 2018https://github.com/microsoft/TypeScript/issues/26043#issuecomment-409305477
#6606https://github.com/microsoft/TypeScript/issues/6606
#6606 (comment)https://github.com/microsoft/TypeScript/issues/6606#issuecomment-387186188
https://github.com/malash
Malash (malash)https://github.com/malash
on Dec 14, 2018https://github.com/microsoft/TypeScript/issues/26043#issuecomment-447229455
https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.htmlhttps://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html
int0hhttps://github.com/int0h
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Dec 16, 2018https://github.com/microsoft/TypeScript/issues/26043#event-2028965340
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Dec 16, 2018https://github.com/microsoft/TypeScript/issues/26043#issuecomment-447663068
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/26043#event-20415752680
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/26043
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/26043
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%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.