René's URL Explorer Experiment


Title: Suggestion: Allow local types to be declared in interfaces · Issue #9889 · microsoft/TypeScript · GitHub

Open Graph Title: Suggestion: Allow local types to be declared in interfaces · Issue #9889 · microsoft/TypeScript

X Title: Suggestion: Allow local types to be declared in interfaces · Issue #9889 · microsoft/TypeScript

Description: I have something like this: export interface Reducer> { add(action: { type: TypeName, reduce: (state: State, action: Payload) => State }): Reducer

Open Graph Description: I have something like this: export interface Reducer> { add(action: { type: TypeName, reduce: (state: State, action: Paylo...

X Description: I have something like this: export interface Reducer<State, Types extends Action<string, any>> { add<TypeName extends string, Payload>(action: { type: TypeName, reduce: (state: St...

Mail addresses
notifications@github.com

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: Allow local types to be declared in interfaces","articleBody":"I have something like this:\n\n```\nexport interface Reducer\u003cState, Types extends Action\u003cstring, any>> {\n\n    add\u003cTypeName extends string, Payload>(action: {\n        type: TypeName,\n        reduce: (state: State, action: Payload) => State\n    }): Reducer\u003cState, Types | Action\u003cTypeName, Payload>>;\n\n    readonly cursorType: Cursor\u003cState, Types>;\n}\n```\n\nThe details aren't that important except to illustrate that a `Reducer` is immutable, and has an `add` method that returns another `Reducer`, but see that the return type has something extra \"unioned\" into it. By repeated chained calls to `add` I can build up a big nasty old type that would be ugly to have fully declare by hand. Fortunately type inference takes care of building the type for me, which is great.\n\nThen elsewhere in my code I want to be able to declare something called a \"cursor\", which needs to have a type that corresponds to the reducer's type. The cursor could be a field in a class so I need to be able to refer to the type so I can declare such a field.\n\nSo I want to provide a simple way to declare a const of the type \"correct kind of cursor for a given reducer\", leveraging the work that the TS compiler already did for me with its type inference.\n\nMy slightly hacky approach, as shown above, is to declare a readonly field `cursorType`. The value of this is at runtime is junk and should not be used! So I need a \"here be dragons\" comment on it. Its only purpose is to be prefixed with `typeof`, e.g.:\n\n```\nconst R = getReducerSomehow();\n\nclass Test {\n    constructor(public readonly myCursor: typeof R.cursorType) { }\n}\n```\n\nTo fill in the `cursorType` field of a `Reducer` I have to do this filth:\n\n```\nnewReducer.cursorType = {} as Cursor\u003cState, Types>;\n```\n\nSo `cursorType` really should never be used as a value. It doesn't even need to exist as a value. It will cause a runtime error if anyone tries to used it as a cursor. Ugh. But how else can I make this elaborately computed type available conveniently?\n\nI'm wondering if TS could allow:\n\n```\nexport interface Reducer\u003cState, Types extends Action\u003cstring, any>> {\n\n    add\u003cTypeName extends string, Payload>(action: {\n        type: TypeName,\n        reduce: (state: State, action: Payload) => State\n    }): Reducer\u003cState, Types | Action\u003cTypeName, Payload>>;\n\n    // not currently possible:\n    type CursorType = Cursor\u003cState, Types>;\n}\n```\n\ni.e. a `type` alias can be added to an interface. So now my implementation of `Reducer` no longer has to do anything. No nasty dummy runtime variable hack required.\n\nAnd my usage example becomes:\n\n```\nconst R = getReducerSomehow();\n\nclass Test {\n    constructor(public readonly myCursor: R.CursorType) { }\n}\n```\n\nThat is, `CursorType` is a type that can be referred to _as if_ it was a member of an instance. Similar I guess to:\n\n```\nnamespace N {\n    export type S = string;\n}\n\nconst s: N.S = \"hi\";\n```\n\nIn which `N` is an object at runtime and yet can also be used to find the type `S`.\n","author":{"url":"https://github.com/danielearwicker","@type":"Person","name":"danielearwicker"},"datePublished":"2016-07-22T12:57:44Z","url":"https://github.com/microsoft/TypeScript/issues/9889"}

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:64178213-f091-a5ed-c69c-94219756cff8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id87BA:4E3C:D003A7:114CA12:6B00F958
html-safe-noncea1a287a71d6721032063c9cf62b63a55a1412987d96830cc5527073243a3a9b5
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4N0JBOjRFM0M6RDAwM0E3OjExNENBMTI6NkIwMEY5NTgiLCJ2aXNpdG9yX2lkIjoiODM0OTM2NDg1MTI1MTkzNTU3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac704d1218f0670b85cf375d7603e2f8fd7aba4bdb68f03ba0c1cd4fbf9850586e
hovercard-subject-tagissue:167039715
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/9889/issue_layout
twitter:imagehttps://opengraph.githubassets.com/daf7b6cd680b3ea02e941dbe104f4fb7df623a45283b846e3ca136892bbe67ed/microsoft/TypeScript/issues/9889
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/daf7b6cd680b3ea02e941dbe104f4fb7df623a45283b846e3ca136892bbe67ed/microsoft/TypeScript/issues/9889
og:image:altI have something like this: export interface Reducer> { add(action: { type: TypeName, reduce: (state: State, action: Paylo...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamedanielearwicker
hostnamegithub.com
expected-hostnamegithub.com
Nonee208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187
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
release7dafd017fb7809a839c443dba08622af38e63c09
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/9889#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F9889
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%2F9889
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/9889
Reloadhttps://github.com/microsoft/TypeScript/issues/9889
Reloadhttps://github.com/microsoft/TypeScript/issues/9889
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/9889
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9889
Suggestion: Allow local types to be declared in interfaceshttps://github.com/microsoft/TypeScript/issues/9889#top
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/danielearwicker
Daniel Earwicker (danielearwicker)https://github.com/danielearwicker
on Jul 22, 2016https://github.com/microsoft/TypeScript/issues/9889#issue-167039715
https://github.com/yortus
Troy Gerwien (yortus)https://github.com/yortus
on Jul 22, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-234569233
#8358https://github.com/microsoft/TypeScript/issues/8358
#8308https://github.com/microsoft/TypeScript/issues/8308
https://github.com/danielearwicker
Daniel Earwicker (danielearwicker)https://github.com/danielearwicker
on Jul 22, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-234678763
Troy Gerwien (@yortus)https://github.com/yortus
#8308https://github.com/microsoft/TypeScript/issues/8308
#8358https://github.com/microsoft/TypeScript/issues/8358
#2625https://github.com/microsoft/TypeScript/issues/2625
#8308https://github.com/microsoft/TypeScript/issues/8308
Mohamed Hegazy (@mhegazy)https://github.com/mhegazy
https://github.com/yortus
Troy Gerwien (yortus)https://github.com/yortus
on Jul 23, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-234689426
#6606https://github.com/microsoft/TypeScript/issues/6606
https://github.com/dead-claudia
Claudia Meadows (dead-claudia)https://github.com/dead-claudia
on Sep 3, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-244569111
Daniel Earwicker (@danielearwicker)https://github.com/danielearwicker
https://github.com/dead-claudia
Claudia Meadows (dead-claudia)https://github.com/dead-claudia
on Sep 3, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-244569233
https://github.com/danielearwicker
Daniel Earwicker (danielearwicker)https://github.com/danielearwicker
on Sep 4, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-244605179
https://github.com/dead-claudia
Claudia Meadows (dead-claudia)https://github.com/dead-claudia
on Sep 5, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-244647917
Daniel Earwicker (@danielearwicker)https://github.com/danielearwicker
https://github.com/HerringtonDarkholme
Herrington Darkholme (HerringtonDarkholme)https://github.com/HerringtonDarkholme
on Sep 29, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-250431769
https://github.com/dead-claudia
Claudia Meadows (dead-claudia)https://github.com/dead-claudia
on Sep 29, 2016https://github.com/microsoft/TypeScript/issues/9889#issuecomment-250553532
1https://github.com/Microsoft/TypeScript/issues/5453
2https://github.com/Microsoft/TypeScript/issues/1213
#9889 (comment)https://github.com/microsoft/TypeScript/issues/9889#issuecomment-250431769
https://github.com/notifications/unsubscribe-auth/AERrBEmc4VAUblspLbuQqXQVLNiIXsCqks5qu5ZLgaJpZM4JSu-2https://github.com/notifications/unsubscribe-auth/AERrBEmc4VAUblspLbuQqXQVLNiIXsCqks5qu5ZLgaJpZM4JSu-2
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
on Oct 24, 2016https://github.com/microsoft/TypeScript/issues/9889#event-834514423
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 24, 2016https://github.com/microsoft/TypeScript/issues/9889#event-834514684
https://github.com/dead-claudia
Claudia Meadows (dead-claudia)https://github.com/dead-claudia
on Jan 14, 2017https://github.com/microsoft/TypeScript/issues/9889#issuecomment-272629886
https://github.com/dead-claudia
Claudia Meadows (dead-claudia)https://github.com/dead-claudia
on Feb 14, 2017https://github.com/microsoft/TypeScript/issues/9889#issuecomment-279603582
https://github.com/alexeygolev
Alexey Golev (alexeygolev)https://github.com/alexeygolev
on Mar 8, 2017https://github.com/microsoft/TypeScript/issues/9889#issuecomment-285143002
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
on Jul 22, 2020https://github.com/microsoft/TypeScript/issues/9889#event-3577361854
Michał Wadas (Ginden)https://github.com/Ginden
Allow types inside of class #62610https://github.com/microsoft/TypeScript/issues/62610
on Oct 16, 2025https://github.com/microsoft/TypeScript/issues/9889#event-20320538996
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/9889
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/9889
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%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.