René's URL Explorer Experiment


Title: Generic namespaces · Issue #19728 · microsoft/TypeScript · GitHub

Open Graph Title: Generic namespaces · Issue #19728 · microsoft/TypeScript

X Title: Generic namespaces · Issue #19728 · microsoft/TypeScript

Description: REVISED: My initial proposal was wrong, here is a revised version. I have a library that exports a collection of interrelated interfaces, classes, and functions, which operate collaboratively on a single generic type. For instance, you c...

Open Graph Description: REVISED: My initial proposal was wrong, here is a revised version. I have a library that exports a collection of interrelated interfaces, classes, and functions, which operate collaboratively on a ...

X Description: REVISED: My initial proposal was wrong, here is a revised version. I have a library that exports a collection of interrelated interfaces, classes, and functions, which operate collaboratively on a ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic namespaces","articleBody":"**REVISED: My initial proposal was wrong, here is a revised version.**\r\n\r\nI have a library that exports a collection of interrelated interfaces, classes, and functions, which operate collaboratively on a single generic type. For instance, you can use them to perform operations on bot messages, game actions, or IoT events, but typically you'd only ever be working with one of those at a time. So the fact that the library is generic gives it broad appeal to a wide variety of developers, but is not itself of value to a given developer. (Contrast with RxJS where solid generic support has specific value to a given developer, because they will likely use it with a wide variety of types in a given project.)\r\n\r\nAn unfortunate consequence of the way the components of this library come together is that they are sometimes very resistant to type inference, so many invocations end up requiring a type decoration, which creates an enormous amount of visual noise. It's a terrible developer experience.\r\n\r\nWhat I have now is:\r\n\r\n```ts\r\n// Library\r\nexport class Class\u003cT> {\r\n}\r\nexport function func\u003cT>(..) {\r\n}\r\n\r\n// Library Consume\r\nimport { Class, Interface, func  } from 'my-library';\r\n\r\n// frequently need to spell out Class\u003cBot>, Interface\u003cBot>, and func\u003cBot>\r\n```\r\n\r\nType aliases help a little, because I can do:\r\n\r\n```ts\r\ntype BotInterface = Interface\u003cBot>;\r\n```\r\n\r\nBut there is no equivalent for functions and classes. And even if there were, that would still make it painful to write my library, because it would be using generics everywhere when what I really want to do is write my library with just a single top-level generic. And it would still make it overly painful to consume my library, because aliases would have to be manually created for every component in the library. What I want is a *generic namespace*:\r\n\r\n```ts\r\n// Library\r\nexport namespace\u003cT> {\r\n    export class Class {\r\n    }\r\n    export function func(...) {\r\n    }\r\n}\r\n\r\n// Library Consumer\r\nimport { MyNamespace } from 'my-library';\r\nconst { Class, Interface, func } = MyNamespace\u003cBot>;\r\n\r\n// just use Class, Interface, and func\r\n```\r\n\r\nWorkarounds: I tried mimicking this by creating a generic factory class, but it is a huge hack and not powerful enough. There is a good reason namespaces exist in TypeScript, and adding generics would make them much more powerful. As it stands, the only real workaround -- which I have been forced to take, and is obviously unsustainable and unmaintainable -- is to fork the library into one version for each type.","author":{"url":"https://github.com/billba","@type":"Person","name":"billba"},"datePublished":"2017-11-03T22:22:35Z","url":"https://github.com/microsoft/TypeScript/issues/19728"}

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:502f3968-6654-a76f-9af1-0bdf1caa8016
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idD99A:3DD488:691DE2:873763:6B00E175
html-safe-noncefc5b33b8d368736b3e6a32e51b1e0511bae2d29906e1a3e847785ba34fa2f3f5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOTlBOjNERDQ4ODo2OTFERTI6ODczNzYzOjZCMDBFMTc1IiwidmlzaXRvcl9pZCI6IjUyNDY1NzgyNjM5NjY5Mjg1MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac4510fd9332e8fcc63f9043f9ab9194172baba11f5b5278699a45feb8b899bd7c
hovercard-subject-tagissue:271134315
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/19728/issue_layout
twitter:imagehttps://opengraph.githubassets.com/70f223ec158e1d71d1e34896adf8a52bd11bb4cf12548d7a2b3431bc91417039/microsoft/TypeScript/issues/19728
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/70f223ec158e1d71d1e34896adf8a52bd11bb4cf12548d7a2b3431bc91417039/microsoft/TypeScript/issues/19728
og:image:altREVISED: My initial proposal was wrong, here is a revised version. I have a library that exports a collection of interrelated interfaces, classes, and functions, which operate collaboratively on a ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebillba
hostnamegithub.com
expected-hostnamegithub.com
None043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf
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
release5425dc24e8bd8d6fca9641a12afc984825a43875
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/19728#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F19728
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%2F19728
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/19728
Reloadhttps://github.com/microsoft/TypeScript/issues/19728
Reloadhttps://github.com/microsoft/TypeScript/issues/19728
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests309 (309)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/19728
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/19728
Generic namespaceshttps://github.com/microsoft/TypeScript/issues/19728#top
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 3, 2017https://github.com/microsoft/TypeScript/issues/19728#issue-271134315
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 4, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-341902914
Bill Barnes (billba)https://github.com/billba
on Nov 4, 2017https://github.com/microsoft/TypeScript/issues/19728#event-1326097391
https://github.com/aluanhaddad
Aluan Haddad (aluanhaddad)https://github.com/aluanhaddad
on Nov 4, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-341938720
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 5, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-341989915
Aluan Haddad (@aluanhaddad)https://github.com/aluanhaddad
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 6, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-342187157
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 6, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-342201074
https://github.com/aluanhaddad
Aluan Haddad (aluanhaddad)https://github.com/aluanhaddad
on Nov 7, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-342336087
Bill Barnes (@billba)https://github.com/billba
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 7, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-342532460
https://github.com/aluanhaddad
Aluan Haddad (aluanhaddad)https://github.com/aluanhaddad
on Nov 7, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-342543675
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 7, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-342546454
https://github.com/billba
Bill Barnes (billba)https://github.com/billba
on Nov 7, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-342605665
https://github.com/aluanhaddad
Aluan Haddad (aluanhaddad)https://github.com/aluanhaddad
on Nov 10, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-343422295
#17574https://github.com/microsoft/TypeScript/issues/17574
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Nov 14, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-344408820
#17574https://github.com/microsoft/TypeScript/issues/17574
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 Nov 14, 2017https://github.com/microsoft/TypeScript/issues/19728#event-1341834354
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Nov 29, 2017https://github.com/microsoft/TypeScript/issues/19728#issuecomment-347707487
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 Nov 29, 2017https://github.com/microsoft/TypeScript/issues/19728#event-1362548725
microsofthttps://github.com/microsoft
on Jun 14, 2018https://github.com/microsoft/TypeScript/issues/19728#event-1682115737
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/19728
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/19728
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.