René's URL Explorer Experiment


Title: [Feature Request] Future-proof always-aliasing/never-expanding of mapped/intersection/union/etc. types · Issue #35654 · microsoft/TypeScript · GitHub

Open Graph Title: [Feature Request] Future-proof always-aliasing/never-expanding of mapped/intersection/union/etc. types · Issue #35654 · microsoft/TypeScript

X Title: [Feature Request] Future-proof always-aliasing/never-expanding of mapped/intersection/union/etc. types · Issue #35654 · microsoft/TypeScript

Description: Search Terms Force TS to always alias type, optional property, never expand type Suggestion It would be nice to have a way to annotate a type alias and tell TS, "As much as possible, do not expand this type alias in emit". I don't know w...

Open Graph Description: Search Terms Force TS to always alias type, optional property, never expand type Suggestion It would be nice to have a way to annotate a type alias and tell TS, "As much as possible, do not expand ...

X Description: Search Terms Force TS to always alias type, optional property, never expand type Suggestion It would be nice to have a way to annotate a type alias and tell TS, "As much as possible, do not ex...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Feature Request] Future-proof always-aliasing/never-expanding of mapped/intersection/union/etc. 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.\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, especially the \"Common Feature Requests\" section: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\n-->\r\n\r\n## Search Terms\r\n\r\n\u003c!-- List of keywords you searched for before creating this issue. Write them down here so that others can find this suggestion more easily -->\r\n\r\nForce TS to always alias type, optional property, never expand type\r\n\r\n## Suggestion\r\n\r\nIt would be nice to have a way to annotate a type alias and tell TS, \"As much as possible, do not expand this type alias in emit\". I don't know what syntax it should have. But maybe,\r\n```ts\r\ntype interface PleaseDoNotExpand\u003cT> = /*complex type*/;\r\n```\r\n\r\nIn all aspects, the above is a type alias, except for the fact that its type will not expand in emit (as much as possible).\r\n\r\n`class` and `interface` types have this behaviour. Their identifiers are used as much as possible in emit.\r\n\r\nThe \"readability\" of a particular emit is almost always subjective. So, giving developers some control over the emit can make code easier to understand.\r\n\r\n-----\r\n\r\nHere's an example, where using a type alias in a union causes the type alias' identifier to not be used in emit,\r\n```ts\r\ntype PleaseDoNotExpand\u003cT> =\r\n    | T\r\n    | { x : T }\r\n;\r\n\r\n/*\r\nExpected: const a: PleaseDoNotExpand\u003cnumber>\r\nActual  : const a: PleaseDoNotExpand\u003cnumber>\r\n*/\r\ndeclare const a: PleaseDoNotExpand\u003cnumber>;\r\n\r\n\r\n/*\r\nExpected: const b: PleaseDoNotExpand\u003cnumber>|undefined\r\nActual  : const b: number | {x: number;} | undefined\r\n*/\r\ndeclare const b: PleaseDoNotExpand\u003cnumber>|undefined;\r\n```\r\n\r\nIf `PleaseDoNotExpand\u003c>` were a `class` or `interface`, we would have `const b: PleaseDoNotExpand\u003cnumber>|undefined`\r\n\r\n## Use Cases\r\n\r\n### What do you want to use this for?\r\n\r\n+ Better emit for `.d.ts` files\r\n+ Better emit for tooltip hover\r\n+ Better emit for error messages\r\n\r\nSome type aliases are hundreds of lines long, after expansion. These type aliases usually have short, intuitive identifiers. But those identifiers tend to get lost when used in union types (and optional properties). See https://github.com/microsoft/TypeScript/issues/35616 for more examples.\r\n\r\n### What shortcomings exist with current approaches?\r\n\r\nThere is no \"general purpose\" workaround for the current problem.\r\n\r\nSo far, I've thought of two workarounds. But they only work for very specific use cases.\r\n\r\n#### Workaround 1: The type alias has statically known members\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/34777\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/34777#issuecomment-551993933\r\n\r\nThe idea is to use an `interface` to extend the type alias. From that point, only the `interface`'s identifier is used in emit. This has the most desirable behaviour. If it could be extended to work for all use cases, then I wouldn't have this feature request.\r\n\r\n#### Workdaround 2: The type alias is being removed by unions/optional properties\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/35616\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/35616#issuecomment-564894944\r\n\r\nThe idea is to create a new type alias that is a union of the original type and the new union elements. However, it does not always work and I don't know why. But this is better than always expanding.\r\n\r\n## Examples\r\n\r\n\u003c!-- Show how this would be used and what the behavior would be -->\r\n\r\n```ts\r\n//No idea about syntax\r\ntype interface PleaseDoNotExpand\u003cT> =\r\n    | T\r\n    | { x : T }\r\n;\r\n\r\n/*\r\nconst a: PleaseDoNotExpand\u003cnumber>\r\n*/\r\ndeclare const a: PleaseDoNotExpand\u003cnumber>;\r\n\r\n\r\n/*\r\nconst b: PleaseDoNotExpand\u003cnumber>|undefined\r\n*/\r\ndeclare const b: PleaseDoNotExpand\u003cnumber>|undefined;\r\n\r\n/*\r\n//It makes sense to lose the identifier at this point\r\nconst c: number\r\n*/\r\ndeclare const c: Extract\u003cPleaseDoNotExpand\u003cnumber>, number>;\r\n\r\n/*\r\n//It makes sense to lose the identifier at this point\r\nconst c: { x : number }\r\n*/\r\ndeclare const d: Exclude\u003cPleaseDoNotExpand\u003cnumber>, number>;\r\n```\r\n\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [X] 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. library functionality, non-ECMAScript syntax with JavaScript output, etc.)\r\n* [X] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n\r\n## Related\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/34556 asks to never alias a type. This asks to always alias a type.","author":{"url":"https://github.com/AnyhowStep","@type":"Person","name":"AnyhowStep"},"datePublished":"2019-12-12T19:43:28Z","url":"https://github.com/microsoft/TypeScript/issues/35654"}

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:225950a2-f49d-b506-59cb-c15b755ccf07
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idA506:19F84C:2D13435:394FCE6:6B01A2A9
html-safe-nonceca2ea23cb92a2d58a9e29e7b63c4d1329e7c4e0d9df66a9a1d7ad73f447736e6
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBNTA2OjE5Rjg0QzoyRDEzNDM1OjM5NEZDRTY6NkIwMUEyQTkiLCJ2aXNpdG9yX2lkIjoiMTYyNDY2ODUyOTM3MjUzNzUxMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac232284a03f31fc151ec145fe072d9ce551a23817c6b46634a7c55848cb4287ad
hovercard-subject-tagissue:537176460
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/35654/issue_layout
twitter:imagehttps://opengraph.githubassets.com/8dfe50e83c88adc378f61a87e10f6d1159c204e5efd71a3ff3e8cd265292079e/microsoft/TypeScript/issues/35654
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/8dfe50e83c88adc378f61a87e10f6d1159c204e5efd71a3ff3e8cd265292079e/microsoft/TypeScript/issues/35654
og:image:altSearch Terms Force TS to always alias type, optional property, never expand type Suggestion It would be nice to have a way to annotate a type alias and tell TS, "As much as possible, do not expand ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAnyhowStep
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/35654#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F35654
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%2F35654
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/35654
Reloadhttps://github.com/microsoft/TypeScript/issues/35654
Reloadhttps://github.com/microsoft/TypeScript/issues/35654
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/35654
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35654
#42149https://github.com/microsoft/TypeScript/pull/42149
[Feature Request] Future-proof always-aliasing/never-expanding of mapped/intersection/union/etc. typeshttps://github.com/microsoft/TypeScript/issues/35654#top
#42149https://github.com/microsoft/TypeScript/pull/42149
https://github.com/ahejlsberg
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
TypeScript 4.2.0https://github.com/microsoft/TypeScript/milestone/129
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Dec 12, 2019https://github.com/microsoft/TypeScript/issues/35654#issue-537176460
#35616https://github.com/microsoft/TypeScript/issues/35616
#34777https://github.com/microsoft/TypeScript/issues/34777
#34777 (comment)https://github.com/microsoft/TypeScript/issues/34777#issuecomment-551993933
#35616https://github.com/microsoft/TypeScript/issues/35616
#35616 (comment)https://github.com/microsoft/TypeScript/issues/35616#issuecomment-564894944
TypeScript's Design Goalshttps://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
#34556https://github.com/microsoft/TypeScript/issues/34556
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
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Jan 27, 2020https://github.com/microsoft/TypeScript/issues/35654#event-2983537478
https://github.com/EdwardDrapkin
Edward Drapkin (EdwardDrapkin)https://github.com/EdwardDrapkin
on Feb 26, 2020https://github.com/microsoft/TypeScript/issues/35654#issuecomment-591605369
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Feb 26, 2020https://github.com/microsoft/TypeScript/issues/35654#issuecomment-591608431
https://github.com/EdwardDrapkin
Edward Drapkin (EdwardDrapkin)https://github.com/EdwardDrapkin
on Feb 26, 2020https://github.com/microsoft/TypeScript/issues/35654#issuecomment-591647972
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Oct 8, 2020https://github.com/microsoft/TypeScript/issues/35654#issuecomment-705395904
https://user-images.githubusercontent.com/5655961/95429630-aa8a7d80-0918-11eb-9b43-7775a254307d.png
https://user-images.githubusercontent.com/5655961/95429729-c5f58880-0918-11eb-8688-6a6625eff8ec.png
https://github.com/ClaireNeveu
Claire Neveu (ClaireNeveu)https://github.com/ClaireNeveu
on Oct 11, 2020https://github.com/microsoft/TypeScript/issues/35654#issuecomment-706723840
AnyhowStephttps://github.com/AnyhowStep
on Nov 10, 2020https://github.com/microsoft/TypeScript/issues/35654#event-3981179322
https://github.com/marijnh
Marijn Haverbeke (marijnh)https://github.com/marijnh
on Dec 23, 2020https://github.com/microsoft/TypeScript/issues/35654#issuecomment-750144800
#42075https://github.com/microsoft/TypeScript/issues/42075
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Dec 29, 2020https://github.com/microsoft/TypeScript/issues/35654#event-4155738494
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
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 Jan 9, 2021https://github.com/microsoft/TypeScript/issues/35654#event-4186580152
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
TypeScript 4.2.0https://github.com/microsoft/TypeScript/milestone/129
on Jan 9, 2021https://github.com/microsoft/TypeScript/issues/35654#event-4186580442
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#42149https://github.com/microsoft/TypeScript/pull/42149
on Jan 9, 2021https://github.com/microsoft/TypeScript/issues/35654#event-4186581730
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Jan 9, 2021https://github.com/microsoft/TypeScript/issues/35654#issuecomment-757347343
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/35654
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35654
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
TypeScript 4.2.0https://github.com/microsoft/TypeScript/milestone/129
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.