René's URL Explorer Experiment


Title: Symbols produced by an alias of the Symbol constructor cannot be used as object keys in types/interfaces/classes, etc. · Issue #53282 · microsoft/TypeScript · GitHub

Open Graph Title: Symbols produced by an alias of the Symbol constructor cannot be used as object keys in types/interfaces/classes, etc. · Issue #53282 · microsoft/TypeScript

X Title: Symbols produced by an alias of the Symbol constructor cannot be used as object keys in types/interfaces/classes, etc. · Issue #53282 · microsoft/TypeScript

Description: Bug Report Symbols returned by an alias of the global Symbol constructor cannot be used as objects keys. See this playground example. In and of itself this is not a bug per se, but it can result in increase bundle size when using a minif...

Open Graph Description: Bug Report Symbols returned by an alias of the global Symbol constructor cannot be used as objects keys. See this playground example. In and of itself this is not a bug per se, but it can result in...

X Description: Bug Report Symbols returned by an alias of the global Symbol constructor cannot be used as objects keys. See this playground example. In and of itself this is not a bug per se, but it can result in...

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.112.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Symbols produced by an alias of the Symbol constructor cannot be used as object keys in types/interfaces/classes, etc.","articleBody":"# Bug Report\r\n\r\nSymbols returned by an alias of the global Symbol constructor cannot be used as objects keys. See this [playground example](https://www.typescriptlang.org/play?ts=4.9.5&ssl=14&ssc=1&pln=13&pc=20#code/MYewdgzgLgBAyjAvPAngWwEYgDYG4CwAUEaJLHOltgPoDWApigIJLwAUAlAYadKpjjqMAQqziduvcpUEMUAYTESiRKCgAO9GABUN9AOoBLKAAsKA7AGlGrAN5EYMANrmqQ5gF0AXDDABXTHoAJwdnV1kRb18AjGDQlxkaOXko-0CQwhgAX24HKRg0AENTVgBZYpNcnnA+ADNWNhQfNNigjmaY4KQAPhh7TJhselgAD1Yi0wA6QowIRq5QseQJk0m0QzA2EYAaGABaAFYFgaWCisnsEABzLY5QoOG-ILAYEe4slUJatj2ARgAGY5AA).\r\n\r\nIn and of itself this is not a bug per se, but it can result in increase bundle size when using a minifier such as terser. Terser does not mangle global names such as  Math, Symbol, etc. (see: https://github.com/terser/terser/issues/1337), so a common trick to avoid them reappearing in minified code is to assign the global name to a local variable.\r\n\r\nFor instance, consider the following typescript code that uses the globals Symbol and Math: [playground link](https://www.typescriptlang.org/play?ts=4.9.5&ssl=20&ssc=1&pln=1&pc=1#code/LAKAxg9gdgzgLgAgMoE8C2AjCAbA+gawFMUBBBAXmXS2wAoBKAblElkVUxwOICEKrOdJi2jwBNbigDC-DjQbMQoOCgAOhBABU1hAOoBLOAAs5OANLF+Ab1AIEAbVN4ipALoAuBFACumQgCdbBydJHg8vXwwAoMdqLhcpcJ8-QJAEAF9FETYEADN+WhRPZKj-emLIgIoAPgQbNIRsQkQAD34AWQBDYwA6TowYQuEGtsou3rR9KFoWgBoEAFoAVmG7UYRxox7sCABzGfog-2bvfygEFsV00FBc2gWARgAGYaA)\r\n\r\n```\r\nconst Symbol_keyA = Symbol();\r\nconst Symbol_keyB = Symbol();\r\nconst Symbol_keyC = Symbol();\r\n\r\ntype TypeWithSymbolKey = {\r\n  [Symbol_keyA]: number\r\n  [Symbol_keyB]: number\r\n  [Symbol_keyC]: number\r\n };\r\n\r\nconst f = (y: number): number => {\r\n  let x = Math.abs(y);\r\n  x = Math.min(x, -5);\r\n  x = Math.log(x)\r\n  return x;\r\n}\r\n\r\nf(-10);\r\n```\r\nwhen compiled to javascript by TS it generates the following output:\r\n\r\n```\r\n\"use strict\";\r\nconst Symbol_keyA = Symbol();\r\nconst Symbol_keyB = Symbol();\r\nconst Symbol_keyC = Symbol();\r\nconst f = (y) => {\r\n    let x = Math.abs(y);\r\n    x = Math.min(x, -5);\r\n    x = Math.log(x);\r\n    return x;\r\n};\r\nf(-10);\r\n```\r\nand when minified using terser you get the following output (you can try this using https://try.terser.org):\r\n\r\n```\r\nSymbol(),Symbol(),Symbol();(l=>{let a=Math.abs(l);a=Math.min(a,-5),a=Math.log(a)})(-10);\r\n```\r\n\r\n\r\nNow consider this minor tweak to the original code, which aliases the global Math name to a local variable: [playground link](https://www.typescriptlang.org/play?ts=4.9.5&ssl=22&ssc=1&pln=2&pc=2#code/LAKAxg9gdgzgLgAgMoE8C2AjCAbA+gawFMUBBBAXmXS2wAoBKAblElkVUxwOICEKrOdJi2jwBNbigDC-DjQbMQoOCgAOhBABU1hAOoBLOAAs5OANLF+Ab1AIEAbVN4ipALoAuBFACumQgCdbBydJHg8vXwwAoMdqLhcpcJ8-QJAEAF9FW1YxNABDY34AWQKjLPBRRAAzfloUT2So-3oGyICKAD4EGzSEbEJEAA9+fOMAOjyMGDrhXuHKUaMxtH0oWkGAGgQAWgBWWbt5hEWx7AgAc3X6IP8B738oBEHFdNBQKtptgEYABlmgA\r\n)\r\n\r\n```\r\n\r\nconst Symbol_keyA = Symbol();\r\nconst Symbol_keyB = Symbol();\r\nconst Symbol_keyC = Symbol();\r\n\r\ntype TypeWithSymbolKey = {\r\n  [Symbol_keyA]: number\r\n  [Symbol_keyB]: number\r\n  [Symbol_keyC]: number\r\n };\r\n\r\n const math = Math;\r\n\r\nconst f = (y: number): number => {\r\n  let x = math.abs(y);\r\n  x = math.min(x, -5);\r\n  x = math.log(x)\r\n  return x;\r\n}\r\n\r\nf(-10);\r\n```\r\nwhen compiled to javascript by TS it generates the following output:\r\n\r\n```\r\n\"use strict\";\r\nconst Symbol_keyA = Symbol();\r\nconst Symbol_keyB = Symbol();\r\nconst Symbol_keyC = Symbol();\r\nconst math = Math;\r\nconst f = (y) => {\r\n    let x = math.abs(y);\r\n    x = math.min(x, -5);\r\n    x = math.log(x);\r\n    return x;\r\n};\r\nf(-10);\r\n```\r\n\r\nwhich terser can minify to:\r\n\r\n```\r\nSymbol(),Symbol(),Symbol();const l=Math;(o=>{let b=l.abs(o);b=l.min(b,-5),b=l.log(b)})(-10);\r\n```\r\n\r\nObviously in this small example there isn't a significant difference in minified size, but in a large library that includes hundreds of calls to a top level name, this reduction can be significant. Its not uncommon to re-export math functions from an internal module to enable this type of minified output when one is focused on reducing output size.\r\n\r\nUnfortunately, for libraries written in TS that choose to use symbols for object keys, class methods, etc. the resulting output can become littered with invocations of the Symbol constructor and there is no typesafe way in typescript to work around this.\r\n\r\n### 🔎 Search Terms\r\n\r\nSymbol\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n4.95\r\n\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about Symbol\r\n\r\n### ⏯ Playground Link\r\n\r\nSymbols returned from alias to Symbol not working as keys: [playground example](https://www.typescriptlang.org/play?ts=4.9.5&ssl=14&ssc=1&pln=13&pc=20#code/MYewdgzgLgBAyjAvPAngWwEYgDYG4CwAUEaJLHOltgPoDWApigIJLwAUAlAYadKpjjqMAQqziduvcpUEMUAYTESiRKCgAO9GABUN9AOoBLKAAsKA7AGlGrAN5EYMANrmqQ5gF0AXDDABXTHoAJwdnV1kRb18AjGDQlxkaOXko-0CQwhgAX24HKRg0AENTVgBZYpNcnnA+ADNWNhQfNNigjmaY4KQAPhh7TJhselgAD1Yi0wA6QowIRq5QseQJk0m0QzA2EYAaGABaAFYFgaWCisnsEABzLY5QoOG-ILAYEe4slUJatj2ARgAGY5AA)\r\n\r\n### 💻 Code\r\n\r\n\r\n### 🙁 Actual behavior\r\n\r\nSymbols returned by aliases of the global Symbol constructor are not unique and cannot be used as keys in interfaces and types.\r\n\r\n### 🙂 Expected behavior\r\n\r\nSymbols returned by aliases of the global Symbol constructor should be unique symbols usable as keys in interfaces and types.","author":{"url":"https://github.com/bordoley","@type":"Person","name":"bordoley"},"datePublished":"2023-03-16T01:59:51Z","url":"https://github.com/microsoft/TypeScript/issues/53282"}

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:b091e258-ee13-ed79-e587-89a24df3b19b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9F98:34B9D4:6CE377:9A7C6B:6B04708A
html-safe-nonce26d3587ea287fa6f154e05e0c2ffaaa68286be0e2ed6564680aae2699283bf05
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5Rjk4OjM0QjlENDo2Q0UzNzc6OUE3QzZCOjZCMDQ3MDhBIiwidmlzaXRvcl9pZCI6IjcyNjEyMDYzMTY2ODgxMDk3MDYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac3d155ef367c2b61f59667fd42546a48dd4474e84cc847f0445cdac5c7c7c128d
hovercard-subject-tagissue:1626553776
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/53282/issue_layout
twitter:imagehttps://opengraph.githubassets.com/9728b67200f9138be7d37c521ae1f3301ba63eeb8766d4af34dceaebf08dd817/microsoft/TypeScript/issues/53282
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/9728b67200f9138be7d37c521ae1f3301ba63eeb8766d4af34dceaebf08dd817/microsoft/TypeScript/issues/53282
og:image:altBug Report Symbols returned by an alias of the global Symbol constructor cannot be used as objects keys. See this playground example. In and of itself this is not a bug per se, but it can result in...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebordoley
hostnamegithub.com
expected-hostnamegithub.com
Noneae8802492f12d3ba4f6b0d814054e617a2a5616b6327bf8555c10cd5b0dc2a6f
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
releasecfb5f24c6e01d85f70804652a5107e5cac03a161
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/53282#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F53282
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%2F53282
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/53282
Reloadhttps://github.com/microsoft/TypeScript/issues/53282
Reloadhttps://github.com/microsoft/TypeScript/issues/53282
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests319 (319)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/53282
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/53282
Symbols produced by an alias of the Symbol constructor cannot be used as object keys in types/interfaces/classes, etc.https://github.com/microsoft/TypeScript/issues/53282#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/bordoley
Dave (bordoley)https://github.com/bordoley
on Mar 16, 2023https://github.com/microsoft/TypeScript/issues/53282#issue-1626553776
playground examplehttps://www.typescriptlang.org/play?ts=4.9.5&ssl=14&ssc=1&pln=13&pc=20#code/MYewdgzgLgBAyjAvPAngWwEYgDYG4CwAUEaJLHOltgPoDWApigIJLwAUAlAYadKpjjqMAQqziduvcpUEMUAYTESiRKCgAO9GABUN9AOoBLKAAsKA7AGlGrAN5EYMANrmqQ5gF0AXDDABXTHoAJwdnV1kRb18AjGDQlxkaOXko-0CQwhgAX24HKRg0AENTVgBZYpNcnnA+ADNWNhQfNNigjmaY4KQAPhh7TJhselgAD1Yi0wA6QowIRq5QseQJk0m0QzA2EYAaGABaAFYFgaWCisnsEABzLY5QoOG-ILAYEe4slUJatj2ARgAGY5AA
terser/terser#1337https://github.com/terser/terser/issues/1337
playground linkhttps://www.typescriptlang.org/play?ts=4.9.5&ssl=20&ssc=1&pln=1&pc=1#code/LAKAxg9gdgzgLgAgMoE8C2AjCAbA+gawFMUBBBAXmXS2wAoBKAblElkVUxwOICEKrOdJi2jwBNbigDC-DjQbMQoOCgAOhBABU1hAOoBLOAAs5OANLF+Ab1AIEAbVN4ipALoAuBFACumQgCdbBydJHg8vXwwAoMdqLhcpcJ8-QJAEAF9FETYEADN+WhRPZKj-emLIgIoAPgQbNIRsQkQAD34AWQBDYwA6TowYQuEGtsou3rR9KFoWgBoEAFoAVmG7UYRxox7sCABzGfog-2bvfygEFsV00FBc2gWARgAGYaA
https://try.terser.orghttps://try.terser.org
playground linkhttps://www.typescriptlang.org/play?ts=4.9.5&ssl=22&ssc=1&pln=2&pc=2#code/LAKAxg9gdgzgLgAgMoE8C2AjCAbA+gawFMUBBBAXmXS2wAoBKAblElkVUxwOICEKrOdJi2jwBNbigDC-DjQbMQoOCgAOhBABU1hAOoBLOAAs5OANLF+Ab1AIEAbVN4ipALoAuBFACumQgCdbBydJHg8vXwwAoMdqLhcpcJ8-QJAEAF9FW1YxNABDY34AWQKjLPBRRAAzfloUT2So-3oGyICKAD4EGzSEbEJEAA9+fOMAOjyMGDrhXuHKUaMxtH0oWkGAGgQAWgBWWbt5hEWx7AgAc3X6IP8B738oBEHFdNBQKtptgEYABlmgA
playground examplehttps://www.typescriptlang.org/play?ts=4.9.5&ssl=14&ssc=1&pln=13&pc=20#code/MYewdgzgLgBAyjAvPAngWwEYgDYG4CwAUEaJLHOltgPoDWApigIJLwAUAlAYadKpjjqMAQqziduvcpUEMUAYTESiRKCgAO9GABUN9AOoBLKAAsKA7AGlGrAN5EYMANrmqQ5gF0AXDDABXTHoAJwdnV1kRb18AjGDQlxkaOXko-0CQwhgAX24HKRg0AENTVgBZYpNcnnA+ADNWNhQfNNigjmaY4KQAPhh7TJhselgAD1Yi0wA6QowIRq5QseQJk0m0QzA2EYAaGABaAFYFgaWCisnsEABzLY5QoOG-ILAYEe4slUJatj2ARgAGY5AA
https://github.com/ExE-Boss
ExE Boss (ExE-Boss)https://github.com/ExE-Boss
on Mar 16, 2023https://github.com/microsoft/TypeScript/issues/53282#issuecomment-1471375198
#37469https://github.com/microsoft/TypeScript/issues/37469
https://github.com/bordoley
Dave (bordoley)https://github.com/bordoley
on Mar 16, 2023https://github.com/microsoft/TypeScript/issues/53282#issuecomment-1471779883
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 Mar 16, 2023https://github.com/microsoft/TypeScript/issues/53282#event-8771493906
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Mar 16, 2023https://github.com/microsoft/TypeScript/issues/53282#issuecomment-1472647874
https://github.com/bordoley
Dave (bordoley)https://github.com/bordoley
on Mar 20, 2023https://github.com/microsoft/TypeScript/issues/53282#issuecomment-1476689626
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/53282
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/53282
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

Response headers:
Servergithub.com
Content-Typetext/html; charset=utf-8
Cache-Controlmax-age=0, private, must-revalidate

Viewport: width=device-width


URLs of crawlers that visited me.