René's URL Explorer Experiment


Title: instanceof should not narrow in false branch; or structural assignment to class types should not be allowed · Issue #33481 · microsoft/TypeScript · GitHub

Open Graph Title: instanceof should not narrow in false branch; or structural assignment to class types should not be allowed · Issue #33481 · microsoft/TypeScript

X Title: instanceof should not narrow in false branch; or structural assignment to class types should not be allowed · Issue #33481 · microsoft/TypeScript

Description: TypeScript Version: 3.5.1 Search Terms: instanceof, narrow, false branch Code class A { x! : number } class B { y! : number } //Neither A nor B, nominally //Is A, structurally const aOrB : A|B = { x : 32 }; if (aOrB instanceof A) { const...

Open Graph Description: TypeScript Version: 3.5.1 Search Terms: instanceof, narrow, false branch Code class A { x! : number } class B { y! : number } //Neither A nor B, nominally //Is A, structurally const aOrB : A|B = { ...

X Description: TypeScript Version: 3.5.1 Search Terms: instanceof, narrow, false branch Code class A { x! : number } class B { y! : number } //Neither A nor B, nominally //Is A, structurally const aOrB : A|B = { ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"instanceof should not narrow in false branch; or structural assignment to class types should not be allowed","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. Even if you think you've found a *bug*, please read the FAQ first, especially the Common \"Bugs\" That Aren't Bugs section!\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: https://github.com/Microsoft/TypeScript/wiki/FAQ\r\n\r\nPlease fill in the *entire* template below.\r\n-->\r\n\r\n\u003c!-- Please try to reproduce the issue with `typescript@next`. It may have already been fixed. -->\r\n**TypeScript Version:**  3.5.1\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\n\r\ninstanceof, narrow, false branch\r\n\r\n**Code**\r\n\r\n```ts\r\nclass A {\r\n  x! : number\r\n}\r\nclass B {\r\n  y! : number\r\n}\r\n\r\n//Neither A nor B, nominally\r\n//Is A, structurally\r\nconst aOrB : A|B = { x : 32 };\r\n\r\nif (aOrB instanceof A) {\r\n  const a : A = aOrB; //OK\r\n} else {\r\n  const b : B = aOrB; //Expected to fail; is OK\r\n}\r\n```\r\n\r\n**Expected behavior:**\r\n\r\n`A|B` should not narrow to `B` in the `false` branch.\r\n\r\nIt is possible for `aOrB` to structurally match `A` but not nominally match `A`.\r\n`instanceof` only checks for a nominal match; not structural match.\r\n\r\n**Actual behavior:**\r\n\r\n`A|B` is narrowed to `B` in the `false` branch and will cause run-time bugs.\r\n\r\n**Playground Link:** [Playground](http://www.typescriptlang.org/play/#code/MYGwhgzhAECC0G8BQ1oA8CE0Bc0B2ArgLYBGApgE5IC+SokMAQoitAJ5a6GmU1JIB6AQDkyASwAuAC0px8AewrRGAGgVExeMCBBtBAgJIxYaiBIoFgEghW2668vGehgA8hWa5YAH2YBeRHQcaABmACZoagBufjEAM2gACjcPaE0zMDxgMnkE2ABKFlRgR2cwYPgAlMYo6CFXAGkaaDIQCDIi6BKnCWgSYP8Xdxq6gQBRNAAHMisyABNoCXloOLAxEFqxGEaaIA)\r\n\r\n**Related Issues:** \r\n\r\nhttps://github.com/microsoft/TypeScript/pull/32774\r\n\r\nI'm sure many people have known of this behaviour for a long time, and I never use classes or `instanceof` much. So, I never bothered to create an issue for it. However, the above PR finally motivated me to bring this up.\r\n\r\nI tried to look for \"instanceof narrow false branch\" on the issues page but couldn't find anything related.\r\n\r\nI'm sure this will get closed as \"Working as Intended\" or \"Duplicate\" but I feel like I needed to get this out of my system, anyway =x","author":{"url":"https://github.com/AnyhowStep","@type":"Person","name":"AnyhowStep"},"datePublished":"2019-09-18T03:26:50Z","url":"https://github.com/microsoft/TypeScript/issues/33481"}

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:ba61a64a-60e7-4172-f088-8f33939c3f3b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id978C:14F601:10D83BD:158B188:6B01029D
html-safe-nonce3168ea62124885a868528b7f6b816cbc8f27b96d0b09f7ac13db63d095c2db5a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NzhDOjE0RjYwMToxMEQ4M0JEOjE1OEIxODg6NkIwMTAyOUQiLCJ2aXNpdG9yX2lkIjoiNTk1ODI1Nzg4NDk5MDA3OTY0NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmaca6a81acf730991664b06efd0b69b9db0400a95e477510f6df8aec0d7ea387ed2
hovercard-subject-tagissue:494965662
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/33481/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c0e5ac28e1a35ca339c27da7be619ff7cfca194092e4349ce2b4c10600df0ee7/microsoft/TypeScript/issues/33481
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c0e5ac28e1a35ca339c27da7be619ff7cfca194092e4349ce2b4c10600df0ee7/microsoft/TypeScript/issues/33481
og:image:altTypeScript Version: 3.5.1 Search Terms: instanceof, narrow, false branch Code class A { x! : number } class B { y! : number } //Neither A nor B, nominally //Is A, structurally const aOrB : A|B = { ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAnyhowStep
hostnamegithub.com
expected-hostnamegithub.com
Nonecb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124
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
release2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/33481#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F33481
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%2F33481
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/33481
Reloadhttps://github.com/microsoft/TypeScript/issues/33481
Reloadhttps://github.com/microsoft/TypeScript/issues/33481
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/33481
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/33481
instanceof should not narrow in false branch; or structural assignment to class types should not be allowedhttps://github.com/microsoft/TypeScript/issues/33481#top
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%22
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Sep 18, 2019https://github.com/microsoft/TypeScript/issues/33481#issue-494965662
Playgroundhttp://www.typescriptlang.org/play/#code/MYGwhgzhAECC0G8BQ1oA8CE0Bc0B2ArgLYBGApgE5IC+SokMAQoitAJ5a6GmU1JIB6AQDkyASwAuAC0px8AewrRGAGgVExeMCBBtBAgJIxYaiBIoFgEghW2668vGehgA8hWa5YAH2YBeRHQcaABmACZoagBufjEAM2gACjcPaE0zMDxgMnkE2ABKFlRgR2cwYPgAlMYo6CFXAGkaaDIQCDIi6BKnCWgSYP8Xdxq6gQBRNAAHMisyABNoCXloOLAxEFqxGEaaIA
#32774https://github.com/microsoft/TypeScript/pull/32774
https://github.com/kitsonk
Kitson Kelly (kitsonk)https://github.com/kitsonk
on Sep 18, 2019https://github.com/microsoft/TypeScript/issues/33481#issuecomment-532507150
#202https://github.com/microsoft/TypeScript/issues/202
#33038https://github.com/microsoft/TypeScript/pull/33038
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Sep 18, 2019https://github.com/microsoft/TypeScript/issues/33481#issuecomment-532536454
#202https://github.com/microsoft/TypeScript/issues/202
#33038https://github.com/microsoft/TypeScript/pull/33038
AnyhowStephttps://github.com/AnyhowStep
on Sep 18, 2019https://github.com/microsoft/TypeScript/issues/33481#event-2642268944
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%22
on Sep 18, 2019https://github.com/microsoft/TypeScript/issues/33481#event-2644241296
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Sep 18, 2019https://github.com/microsoft/TypeScript/issues/33481#issuecomment-532772825
https://github.com/austincummings
Austin Cummings (austincummings)https://github.com/austincummings
on Sep 18, 2019https://github.com/microsoft/TypeScript/issues/33481#issuecomment-532778994
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
#32774https://github.com/microsoft/TypeScript/pull/32774
herehttps://github.com/microsoft/TypeScript/pull/32774#discussion_r314844270
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Sep 19, 2019https://github.com/microsoft/TypeScript/issues/33481#issuecomment-533240684
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Sep 21, 2019https://github.com/microsoft/TypeScript/issues/33481#issuecomment-533826237
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 Sep 21, 2019https://github.com/microsoft/TypeScript/issues/33481#event-2652292723
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/33481#event-20416781139
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/33481
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/33481
Working as IntendedThe behavior described is the intended behavior; this is not a bughttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Working%20as%20Intended%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.