René's URL Explorer Experiment


Title: Improve type inference for generic curried functions · Issue #15016 · microsoft/TypeScript · GitHub

Open Graph Title: Improve type inference for generic curried functions · Issue #15016 · microsoft/TypeScript

X Title: Improve type inference for generic curried functions · Issue #15016 · microsoft/TypeScript

Description: // #-------------- This works type Repeat = (n: number) => (s: string) => string; export const repeat: Repeat = n => s => s.repeat(n); // Sweet! s and n are both inferred! // -------------------------# // #----- Problems begin here type ...

Open Graph Description: // #-------------- This works type Repeat = (n: number) => (s: string) => string; export const repeat: Repeat = n => s => s.repeat(n); // Sweet! s and n are both inferred! // ----------------------...

X Description: // #-------------- This works type Repeat = (n: number) => (s: string) => string; export const repeat: Repeat = n => s => s.repeat(n); // Sweet! s and n are both inferred! // ----------...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Improve type inference for generic curried functions","articleBody":"```ts\r\n// #-------------- This works\r\n\r\ntype Repeat = (n: number) =\u003e (s: string) =\u003e string;\r\nexport const repeat: Repeat = n =\u003e s =\u003e s.repeat(n); // Sweet! s and n are both inferred!\r\n\r\n// -------------------------#\r\n\r\n\r\n// #----- Problems begin here\r\n\r\ntype Repeat2 = (n: number) =\u003e \u003cT extends { repeat(n: number): T }\u003e(repeatable: T) =\u003e T;\r\n\r\n// Only n is inferred as number. Won't work with noImplicitAny enabled\r\nexport const repeat2Broken: Repeat2 = n =\u003e r =\u003e r.repeat(n); \r\n// Workaround is to redeclare everything from the type signature\r\nexport const repeat2Ugly: Repeat2 =\r\n    n =\u003e \u003cT extends { repeat(n: number): T }\u003e(r: T) =\u003e r.repeat(n);\r\n\r\n// -------------------------#\r\n\r\n\r\n// #----------- It gets worse\r\n\r\n// Type inference breaks for all args following the generic one, so even if you use\r\n// the workaround, the next args won't regain inference\r\ntype Repeat3 = \r\n    (n: number) \r\n    =\u003e \u003cT extends { repeat(n: number): T }\u003e(repeatable: T) \r\n    =\u003e (reverse: boolean) \r\n    =\u003e T;\r\n\r\n// Even if you explicitly provide the boilerplate for the generic arg, the boolean arg \r\n// won't be inferred. So the following won't work with noImplicitAny enabled\r\nexport const repeat3UglyAndBroken: Repeat3 =\r\n    n =\u003e \u003cT extends { repeat(n: number): T }\u003e(r: T) =\u003e b =\u003e { ... }\r\n\r\n// You have to add typing for the last arg\r\nexport const repeat3Uglier: Repeat3 =\r\n    n =\u003e \u003cT extends { repeat(n: number): T }\u003e(r: T) =\u003e (b: boolean) =\u003e { ... }\r\n\r\n// -------------------------#\r\n```\r\n\r\nI'd really appreciate better support for good inference in this kind of scenario, whether it is solved by supporting partial generic application or addition of participation of return-types in inference or whatever. \r\n\r\nJS libraries that use a functional programming paradigm often end up loosely or any-ly typed, because you find yourself fighting the type system and adding repetitive type noise all over your code to derive any safety. A couple of examples where better support for FP would be useful:\r\n\r\n - Libraries like React or Apollo make use of curried higher-order functions for solving cross-cutting concerns. In-fact, my original use case comes from React higher-order components\r\n - Popular FP libraries like Ramda become tedious to use in a `noImplicitAny` project because any generic functions passed or received from the library tend to quickly devolve into `{}` unless you repeatedly hand-hold the type system\r\n\r\nHere is my original use-case, if interested:\r\n\r\n```ts\r\nexport type GetState\u003cTState\u003e = () =\u003e TState;\r\nexport type SetState\u003cTState\u003e = (newState: TState) =\u003e void;\r\nexport type StatelessComponent\u003cTProp\u003e = (prop: TProp) =\u003e React.ReactElement\u003cTProp\u003e\r\nexport type StatefulComponent\u003cTProp, TState\u003e = \r\n    (stateAccess: { getState: GetState\u003cTState\u003e, setState: SetState\u003cTState\u003e })\r\n    =\u003e StatelessComponent\u003cTProp\u003e;\r\n\r\ntype ScrollableHOC = \r\n    (options: ScrollableOptions) \r\n    =\u003e \u003cT extends ScrollableProps\u003e(Child: ReactComponent\u003cT\u003e) \r\n    =\u003e StatefulComponent\u003cT, ScrollableState\u003e;\r\n\r\n// The introduction of the Child arg breaks type inference for getState, setState, props\r\nconst scrollable: ScrollableHOC = opts =\u003e Child =\u003e ({ getState, setState }) =\u003e props =\u003e {\r\n    // ...\r\n}\r\n```","author":{"url":"https://github.com/masaeedu","@type":"Person","name":"masaeedu"},"datePublished":"2017-04-05T01:12:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":25},"url":"https://github.com/15016/TypeScript/issues/15016"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:af635299-6dff-7cda-50b8-2fc85f2bdc7e
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB31C:9B7C5:4CBF91:68C3F1:6A629B86
html-safe-nonce586d686dc80a1fb5097e6e2276b9be51939b80fd440e18f4250ac167115e59a3
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzFDOjlCN0M1OjRDQkY5MTo2OEMzRjE6NkE2MjlCODYiLCJ2aXNpdG9yX2lkIjoiNzM2MzUxNDA0ODI4MDk1OTg3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac62390a019d1bdc0929194aae84481bdf24fe7898f0d75defec0a28b495662c31
hovercard-subject-tagissue:219433823
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/15016/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d1484e360c1d9d73311bc4d8f63a9305861dc37292b8c1908fff0123c53e8c42/microsoft/TypeScript/issues/15016
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d1484e360c1d9d73311bc4d8f63a9305861dc37292b8c1908fff0123c53e8c42/microsoft/TypeScript/issues/15016
og:image:alt// #-------------- This works type Repeat = (n: number) => (s: string) => string; export const repeat: Repeat = n => s => s.repeat(n); // Sweet! s and n are both inferred! // ----------------------...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemasaeedu
hostnamegithub.com
expected-hostnamegithub.com
Nonea6443033349a18134b517627f043d4a59a5110337b879810c7229c2c7e28eda0
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
released6c6cacbe32d3ddfd1796fbd1a39b8fb47b87daf
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/15016#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F15016
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F15016
Sign up https://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/15016
Reloadhttps://github.com/microsoft/TypeScript/issues/15016
Reloadhttps://github.com/microsoft/TypeScript/issues/15016
Please reload this pagehttps://github.com/microsoft/TypeScript/issues/15016
microsoft https://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Notifications https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Fork 13.6k https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Star 110k https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Code https://github.com/microsoft/TypeScript
Issues 5k+ https://github.com/microsoft/TypeScript/issues
Pull requests 21 https://github.com/microsoft/TypeScript/pulls
Actions https://github.com/microsoft/TypeScript/actions
Projects https://github.com/microsoft/TypeScript/projects
Models https://github.com/microsoft/TypeScript/models
Wiki https://github.com/microsoft/TypeScript/wiki
Security and quality 0 https://github.com/microsoft/TypeScript/security
Insights https://github.com/microsoft/TypeScript/pulse
Code https://github.com/microsoft/TypeScript
Issues https://github.com/microsoft/TypeScript/issues
Pull requests https://github.com/microsoft/TypeScript/pulls
Actions https://github.com/microsoft/TypeScript/actions
Projects https://github.com/microsoft/TypeScript/projects
Models https://github.com/microsoft/TypeScript/models
Wiki https://github.com/microsoft/TypeScript/wiki
Security and quality https://github.com/microsoft/TypeScript/security
Insights https://github.com/microsoft/TypeScript/pulse
Improve type inference for generic curried functionshttps://github.com/microsoft/TypeScript/issues/15016#top
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
https://github.com/masaeedu
masaeeduhttps://github.com/masaeedu
on Apr 5, 2017https://github.com/microsoft/TypeScript/issues/15016#issue-219433823
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.