René's URL Explorer Experiment


Title: Proposal: strict flag to prevent uninferrable generic types from being inferred as {} · Issue #27288 · microsoft/TypeScript · GitHub

Open Graph Title: Proposal: strict flag to prevent uninferrable generic types from being inferred as {} · Issue #27288 · microsoft/TypeScript

X Title: Proposal: strict flag to prevent uninferrable generic types from being inferred as {} · Issue #27288 · microsoft/TypeScript

Description: I'm sure there an issue or discussion about this I missed, but I couldn't find it via search. Search Terms Generic, infer, default, {}, { }, empty, shape, object Suggestion Behind a new strict mode flag --strictGenericBindings, when bind...

Open Graph Description: I'm sure there an issue or discussion about this I missed, but I couldn't find it via search. Search Terms Generic, infer, default, {}, { }, empty, shape, object Suggestion Behind a new strict mode...

X Description: I'm sure there an issue or discussion about this I missed, but I couldn't find it via search. Search Terms Generic, infer, default, {}, { }, empty, shape, object Suggestion Behind a new str...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Proposal: strict flag to prevent uninferrable generic types from being inferred as {}","articleBody":"I'm sure there an issue or discussion about this I missed, but I couldn't find it via search.\r\n\r\n## Search Terms\r\n\r\nGeneric, infer, default, {}, { }, empty, shape, object\r\n\r\n## Suggestion\r\n\r\nBehind a new `strict` mode flag `--strictGenericBindings`, when binding concrete types to generic type parameters, if a type can't be inferred TSC should throw an error at compile time instead of defaulting to `{}`.\r\n\r\n## Use Cases\r\n\r\nLet's say you have the following Promise:\r\n\r\n```ts\r\nconst p = new Promise(resolve =\u003e resolve(42)) // Promise\u003c{}\u003e\r\np.then(r =\u003e\r\n  r + 4 // Error: Operator '+' cannot be applied to types '{}' and '4'.\r\n)\r\n```\r\n\r\nThis gives an error when you try to use the Promise's result. This experience isn't ideal, because the error is non-local. Looking at the code that threw that error, it's not obvious why `r` is `{}`.\r\n\r\nIf I try to fix this by adding an explicit annotate when I consume `r`, it works:\r\n\r\n```ts\r\np.then((r: number) =\u003e {\r\n  r + 4 // OK\r\n})\r\n```\r\n\r\nBut if I have `strictFunctionTypes` enabled, that breaks because `{}` isn't assignable to `number`:\r\n\r\n```ts\r\np.then((r: number) =\u003e {\r\n  r + 4 // Error: Argument of type '(r: number) =\u003e void' is not assignable to parameter of type '(value: {}) =\u003e void | PromiseLike\u003cvoid\u003e'.\r\n})\r\n```\r\n\r\nThe real fix is to explicitly bind a type parameter when I consume `Promise`:\r\n\r\n```ts\r\nconst p = new Promise\u003cnumber\u003e(resolve =\u003e resolve(42)) \r\np.then(r =\u003e {\r\n  r + 4\r\n})\r\n```\r\n\r\nBut unfortunately, the error messages didn't help me get there.\r\n\r\nA possible solution to this problem is to throw a helpful error message when a generic type parameter can't be inferred. This can help prevent bugs, and help programmers catch bugs earlier:\r\n\r\n```ts\r\nconst p = new Promise(resolve =\u003e resolve(42)) // Error: Unable to infer a generic type for Promise\u003cT\u003e - please bind one explicitly. Eg. new Promise\u003cmyType\u003e(...).\r\np.then(r =\u003e {\r\n  r + 4\r\n})\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n* [ ] This wouldn't be a breaking change in existing TypeScript / JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. new expression-level syntax)\r\n\r\n## Related Issues\r\n\r\n- https://github.com/Microsoft/TypeScript/issues/26809\r\n- https://github.com/Microsoft/TypeScript/issues/10247\r\n","author":{"url":"https://github.com/bcherny","@type":"Person","name":"bcherny"},"datePublished":"2018-09-23T00:00:09.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":12},"url":"https://github.com/27288/TypeScript/issues/27288"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8a71e1ff-fa70-a9ec-ec85-252f51da33e5
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEAC6:307AD9:3A569A:53DDCE:6A61C9CE
html-safe-nonce16c46d4d6bb044c49bf2dcb495002d8ae8df5c416485c28c4241c2e0157255cf
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQUM2OjMwN0FEOTozQTU2OUE6NTNERENFOjZBNjFDOUNFIiwidmlzaXRvcl9pZCI6IjI0MjQyNjA1Njc5Mjg3ODUzNTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac83691aa8d7ad8833847d6b49e9c658fa6fd633ef3051cc57689c0901cc18496c
hovercard-subject-tagissue:362900433
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/27288/issue_layout
twitter:imagehttps://opengraph.githubassets.com/26359dc014fddbff0a4f971edfbc1a64f16944f7dfe27a1c187b150cc748d221/microsoft/TypeScript/issues/27288
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/26359dc014fddbff0a4f971edfbc1a64f16944f7dfe27a1c187b150cc748d221/microsoft/TypeScript/issues/27288
og:image:altI'm sure there an issue or discussion about this I missed, but I couldn't find it via search. Search Terms Generic, infer, default, {}, { }, empty, shape, object Suggestion Behind a new strict mode...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebcherny
hostnamegithub.com
expected-hostnamegithub.com
Noneb2de8c74e5e61e893155ba46ee41bc66170c1644cb795adefa8386d490f7781c
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
released1866027ded575df8a15c731dd8b9986c9483ceb
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/27288#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F27288
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%2F27288
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/27288
Reloadhttps://github.com/microsoft/TypeScript/issues/27288
Reloadhttps://github.com/microsoft/TypeScript/issues/27288
Please reload this pagehttps://github.com/microsoft/TypeScript/issues/27288
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
Proposal: strict flag to prevent uninferrable generic types from being inferred as {}https://github.com/microsoft/TypeScript/issues/27288#top
https://github.com/DanielRosenwasser
CommittedThe team has roadmapped this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Committed%22
ExperimentA fork with an experimental idea which might not make it into masterhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Experiment%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
TypeScript 3.5.0https://github.com/microsoft/TypeScript/milestone/89
https://github.com/bcherny
bchernyhttps://github.com/bcherny
on Sep 23, 2018https://github.com/microsoft/TypeScript/issues/27288#issue-362900433
Generic parameter types are incorrectly inferred as { } #26809https://github.com/microsoft/TypeScript/issues/26809
Function composition challenge for type system #10247https://github.com/microsoft/TypeScript/issues/10247
DanielRosenwasserhttps://github.com/DanielRosenwasser
CommittedThe team has roadmapped this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Committed%22
ExperimentA fork with an experimental idea which might not make it into masterhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Experiment%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
TypeScript 3.5.0https://github.com/microsoft/TypeScript/milestone/89
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.