René's URL Explorer Experiment


Title: No type narrowing for discriminated union type guards on unique symbol properties · Issue #23135 · microsoft/TypeScript · GitHub

Open Graph Title: No type narrowing for discriminated union type guards on unique symbol properties · Issue #23135 · microsoft/TypeScript

X Title: No type narrowing for discriminated union type guards on unique symbol properties · Issue #23135 · microsoft/TypeScript

Description: Note: I know about #10530 but I explain why I think this deserves its own issue in the related issues section below TypeScript Version: 2.9.0-dev.20180403 Search Terms: unique symbol, discriminated union, type guard, narrow, narrowing Co...

Open Graph Description: Note: I know about #10530 but I explain why I think this deserves its own issue in the related issues section below TypeScript Version: 2.9.0-dev.20180403 Search Terms: unique symbol, discriminated...

X Description: Note: I know about #10530 but I explain why I think this deserves its own issue in the related issues section below TypeScript Version: 2.9.0-dev.20180403 Search Terms: unique symbol, discriminated...

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

X: @github

direct link

Domain: github.com

IPv4 address: 140.82.114.3


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"No type narrowing for discriminated union type guards on unique symbol properties","articleBody":"***Note: I know about #10530 but I explain why I think this deserves its own issue in the related issues section below***\r\n\r\n**TypeScript Version:**  2.9.0-dev.20180403\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** \r\nunique symbol, discriminated union, type guard, narrow, narrowing\r\n\r\n**Code**\r\n\r\n```ts\r\ndeclare const kind: unique symbol\r\n\r\ntype Square = {\r\n  readonly [kind]: \"square\"\r\n  length: number\r\n  width: number\r\n}\r\n\r\ntype Circle = {\r\n  readonly [kind]: \"circle\"\r\n  radius: number\r\n}\r\n\r\ntype Shape = Square | Circle\r\n\r\nfunction doesNotNarrow(shape: Shape) {\r\n  if (shape[kind] === \"square\") {\r\n    console.log(shape.length, shape.width) // error length does not exist on Shape \r\n  } else {\r\n    console.log(shape.radius) // error radius does not exist on Shape \r\n  }\r\n}\r\n```\r\n**Expected behavior:**\r\nNo errors because the type should be narrowed inside the if statements.\r\n\r\n**Actual behavior:**\r\nCompile errors because typescript does not narrow the type despite the discriminated union.\r\n\r\n**Playground Link:** \r\n[Link](https://www.typescriptlang.org/play/#src=declare%20const%20kind%3A%20unique%20symbol%0D%0A%0D%0Atype%20Square%20%3D%20%7B%0D%0A%20%20readonly%20%5Bkind%5D%3A%20%22square%22%0D%0A%20%20length%3A%20number%0D%0A%20%20width%3A%20number%0D%0A%7D%0D%0A%0D%0Atype%20Circle%20%3D%20%7B%0D%0A%20%20readonly%20%5Bkind%5D%3A%20%22circle%22%0D%0A%20%20radius%3A%20number%0D%0A%7D%0D%0A%0D%0Atype%20Shape%20%3D%20Square%20%7C%20Circle%0D%0A%0D%0Afunction%20doesNotNarrow(shape%3A%20Shape)%20%7B%0D%0A%20%20if%20(shape%5Bkind%5D%20%3D%3D%3D%20%22square%22)%20%7B%0D%0A%20%20%20%20console.log(shape.length%2C%20shape.width)%20%2F%2F%20error%20length%20does%20not%20exist%20on%20Shape%20%0D%0A%20%20%7D%20else%20%7B%0D%0A%20%20%20%20console.log(shape.radius)%20%2F%2F%20error%20radius%20does%20not%20exist%20on%20Shape%20%0D%0A%20%20%7D%0D%0A%7D)\r\n\r\n**Related Issues:**\r\n\r\n- #10530 _Discriminant property type guard not applied with bracket notation_ \r\n\r\nI know this looks like a straight duplicate but I don't think it should be considered one because symbols aren't mentioned anywhere in that issue or in the titles of any of its duplicates, and `unique symbol` did not exist when that issue was originally considered.\r\n\r\nThe only reason that #10530 hasn't been fixed is because it caused enough of a performance slowdown that it wasn't considered a worthwhile tradeoff. I'm hoping that limiting this to only `unique symbol`s will have a small enough performance impact to make it worthwhile this time.\r\n\r\nUnlike most string keys, symbols can only be used with bracket notation so I think the value proposition here is much higher than it was for string keys. Plus it seems like using a symbol as a discriminant property that doesn't have to worry about conflicting with other property names is one of the most natural use cases for symbols.","author":{"url":"https://github.com/kpdonn","@type":"Person","name":"kpdonn"},"datePublished":"2018-04-04T08:49:29Z","url":"https://github.com/microsoft/TypeScript/issues/23135"}

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:e9264a41-424c-e5de-7bce-e1eb7c0781a2
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idE130:B0736:65650D:902BD6:6B046FC4
html-safe-nonce54ed27d24949b7b54b0f78d9bcd57083a46a834cbd121b38009f7e2fbf1fd7e9
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTMwOkIwNzM2OjY1NjUwRDo5MDJCRDY6NkIwNDZGQzQiLCJ2aXNpdG9yX2lkIjoiMjY3MjcxNDU4MTk0ODAwMjI0NCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac70def36f537b1611f4701f3fd79f8b2de4557e877cf688ca3070314addf08cdd
hovercard-subject-tagissue:311138905
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/23135/issue_layout
twitter:imagehttps://opengraph.githubassets.com/0c8db294ea24dcbfc90bcde0acf1fc068bf9d2199ef960a116d6fe8456350b70/microsoft/TypeScript/issues/23135
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/0c8db294ea24dcbfc90bcde0acf1fc068bf9d2199ef960a116d6fe8456350b70/microsoft/TypeScript/issues/23135
og:image:altNote: I know about #10530 but I explain why I think this deserves its own issue in the related issues section below TypeScript Version: 2.9.0-dev.20180403 Search Terms: unique symbol, discriminated...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamekpdonn
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-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/23135#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F23135
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%2F23135
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/23135
Reloadhttps://github.com/microsoft/TypeScript/issues/23135
Reloadhttps://github.com/microsoft/TypeScript/issues/23135
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/23135
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/23135
No type narrowing for discriminated union type guards on unique symbol propertieshttps://github.com/microsoft/TypeScript/issues/23135#top
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
https://github.com/kpdonn
Kevin Donnelly (kpdonn)https://github.com/kpdonn
on Apr 4, 2018https://github.com/microsoft/TypeScript/issues/23135#issue-311138905
#10530https://github.com/microsoft/TypeScript/issues/10530
Linkhttps://www.typescriptlang.org/play/#src=declare%20const%20kind%3A%20unique%20symbol%0D%0A%0D%0Atype%20Square%20%3D%20%7B%0D%0A%20%20readonly%20%5Bkind%5D%3A%20%22square%22%0D%0A%20%20length%3A%20number%0D%0A%20%20width%3A%20number%0D%0A%7D%0D%0A%0D%0Atype%20Circle%20%3D%20%7B%0D%0A%20%20readonly%20%5Bkind%5D%3A%20%22circle%22%0D%0A%20%20radius%3A%20number%0D%0A%7D%0D%0A%0D%0Atype%20Shape%20%3D%20Square%20%7C%20Circle%0D%0A%0D%0Afunction%20doesNotNarrow(shape%3A%20Shape)%20%7B%0D%0A%20%20if%20(shape%5Bkind%5D%20%3D%3D%3D%20%22square%22)%20%7B%0D%0A%20%20%20%20console.log(shape.length%2C%20shape.width)%20%2F%2F%20error%20length%20does%20not%20exist%20on%20Shape%20%0D%0A%20%20%7D%20else%20%7B%0D%0A%20%20%20%20console.log(shape.radius)%20%2F%2F%20error%20radius%20does%20not%20exist%20on%20Shape%20%0D%0A%20%20%7D%0D%0A%7D
Discriminant property type guard not applied with bracket notation #10530https://github.com/microsoft/TypeScript/issues/10530
#10530https://github.com/microsoft/TypeScript/issues/10530
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Apr 4, 2018https://github.com/microsoft/TypeScript/issues/23135#issuecomment-378676338
#10530https://github.com/microsoft/TypeScript/issues/10530
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Apr 4, 2018https://github.com/microsoft/TypeScript/issues/23135#issuecomment-378676505
#10530https://github.com/microsoft/TypeScript/issues/10530
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 Apr 4, 2018https://github.com/microsoft/TypeScript/issues/23135#event-1556997745
https://github.com/kpdonn
Kevin Donnelly (kpdonn)https://github.com/kpdonn
on Apr 4, 2018https://github.com/microsoft/TypeScript/issues/23135#issuecomment-378715783
#10530https://github.com/microsoft/TypeScript/issues/10530
#10530https://github.com/microsoft/TypeScript/issues/10530
https://github.com/mhegazy
Mohamed Hegazy (mhegazy)https://github.com/mhegazy
on Apr 4, 2018https://github.com/microsoft/TypeScript/issues/23135#issuecomment-378730459
#10530https://github.com/microsoft/TypeScript/issues/10530
#10530https://github.com/microsoft/TypeScript/issues/10530
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Apr 19, 2018https://github.com/microsoft/TypeScript/issues/23135#issuecomment-382886902
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 Apr 19, 2018https://github.com/microsoft/TypeScript/issues/23135#event-1584850743
microsofthttps://github.com/microsoft
on Jul 30, 2018https://github.com/microsoft/TypeScript/issues/23135#event-1761000968
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/23135
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/23135
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

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.