René's URL Explorer Experiment


Title: Control flow analysis overriding an explicit type declaration when the type flows from optional chaining · Issue #50444 · microsoft/TypeScript · GitHub

Open Graph Title: Control flow analysis overriding an explicit type declaration when the type flows from optional chaining · Issue #50444 · microsoft/TypeScript

X Title: Control flow analysis overriding an explicit type declaration when the type flows from optional chaining · Issue #50444 · microsoft/TypeScript

Description: Bug Report I'm not exactly sure if this is a bug or not - CFA rules are not well-documented. I find the present behavior to be quite annoying though 🔎 Search Terms narrowing, control flow analysis, nullable, optional chaining 🕗 Version &...

Open Graph Description: Bug Report I'm not exactly sure if this is a bug or not - CFA rules are not well-documented. I find the present behavior to be quite annoying though 🔎 Search Terms narrowing, control flow analysis,...

X Description: Bug Report I'm not exactly sure if this is a bug or not - CFA rules are not well-documented. I find the present behavior to be quite annoying though 🔎 Search Terms narrowing, control flow analy...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Control flow analysis overriding an explicit type declaration when the type flows from optional chaining","articleBody":"# Bug Report\r\n\r\nI'm not exactly sure if this is a bug or not - CFA rules are not well-documented. I find the present behavior to be quite annoying though\r\n\r\n### 🔎 Search Terms\r\n\r\nnarrowing, control flow analysis, nullable, optional chaining\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n\u003c!-- When did you start seeing this bug occur?\r\n\r\n\"Bugs\" that have existed in TS for a long time are very likely to be FAQs; refer to\r\n  https://github.com/Microsoft/TypeScript/wiki/FAQ#common-bugs-that-arent-bugs\r\n\r\nIf possible, please try testing the nightly version of TS to see if it's already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: [TS nightly playground](https://www.typescriptlang.org/play?ts=4.9.0-dev.20220825#code/PTAEAcFcCdwewM4FMBmkA26CepLNAAYACALluEgsAFQGgAWS0SoARkgMYCGeLcJjaAHcAlvgCSDLgBMI0OK3RIAtglCiBoAIIAVLaABQI5fGglQAclLlKwAG4IOcaUgC0QpKzsikQiwYMnADsEcwcnFwAuUAAlJBIYIJ0bAB4yCjgUUC4OAEdIEWYANQQAYWckLXARAD5QAB9cIJcUESCkWQBebLyC4rKKqpEAfgA6AAoASgMQUDnQAD1hgPCKmbAlgNmuEhIVcHMSOHVoLnBQNuyg0HFxADEAUUC4ELDHCoAmaLiE6CTU9JITI9fKFJAlcouIZ1RqQZqoNodUDdcZTZF1HKg-qQyrVMZTSZTADc63mi2WpKCxw49C4QQA5iwBHBIPT6AZVi4PqTNs9XqBOUgAMzfeKJZIUNI2YGYvrggZQ6owpotRFdEFyiGDaqgYYasFaxUiNHROGq9rSEmzea82atIJcTA4QA8G4BI-Y57xcQp5wyAA)\r\n\r\n- This is the behavior in every version (since 3.7 as that's the version that introduced optional chaining) I tried\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.7.4#code/PTAEAcFcCdwewM4FMBmkA26CepLNAAYACALluEgsAFQGgAWS0SoARkgMYCGeLcJjaAHcAlvgCSDLgBMI0OK3RIAtglCiBoAIIAVLaABQI5fGglQAclLlKwAG4IOcaUgC0QpKzsikQiwYMnADsEcwcnFwAuUAAlJBIYIJ0bAB4yCjgUUC4OAEdIEWYANQQAYWckLXARAD5QAB9cIJcUESCkWQBebLyC4rKKqpEAfgA6AAoASgMQUDnQAD1hgPCKmbAlgNmuEhIVcHMSOHVoLnBQNuyg0HFxADEAUUC4ELDHCoAmaLiE6CTU9JITI9fKFJAlcouIZ1RqQZqoNodUDdcZTZF1HKg-qQyrVMZTSZTADc63mi2WpKCxw49C4QQA5iwBHBIPT6AZVi4PqTNs9XqBOUgAMzfeKJZIUNI2YGYvrggZQ6owpotRFdEFyiGDaqgYYasFaxUiNHROGq9rSEmzea82atIJcTA4QA8G4BI-Y57xcQp5wyAA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\n// purposefully use `@types/*` here because otherwise I had problems with ATA \r\nimport '@types/vscode-webview'\r\n\r\nconst vscode: ReturnType\u003ctypeof acquireVsCodeApi> | undefined = acquireVsCodeApi?.()\r\n//    ^? WebviewApi\u003cunknown> | undefined\r\n\r\nvscode\r\n// ^? WebviewApi\u003cunknown>\r\n\r\n// attempt to wrap in an IIFE\r\nconst vscode2: ReturnType\u003ctypeof acquireVsCodeApi> | undefined = (() => acquireVsCodeApi?.())();\r\n//    ^? WebviewApi\u003cunknown> | undefined\r\n\r\n// no change though\r\nvscode2\r\n// ^? WebviewApi\u003cunknown>\r\n\r\nconst vscode3: ReturnType\u003ctypeof acquireVsCodeApi> | undefined = acquireVsCodeApi ? acquireVsCodeApi() : undefined;\r\n//    ^? WebviewApi\u003cunknown> | undefined\r\n\r\n// finally 🎉\r\nvscode3\r\n// ^? WebviewApi\u003cunknown> | undefined\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nReferencing a variable with the declared type that originates in an expression using optional chaining doesn't include `| undefined` in its type. \r\n\r\nNote that `acquireVsCodeApi` is **always** defined according to the types.\r\n\r\n### 🙂 Expected behavior\r\n\r\nEven though `acquireVsCodeApi` is always defined I would expect my explicit declaration on the assigned variable to win for the purpose of CFA.\r\n\r\nI have an app that is running as a standalone but it's also bundled as a VS Code extension. It's a hussle to include the VS Code types conditionally and it's much easier for us to just add those defs globally and refine this stuff at runtime when needed.\r\n","author":{"url":"https://github.com/Andarist","@type":"Person","name":"Andarist"},"datePublished":"2022-08-25T13:11:52Z","url":"https://github.com/microsoft/TypeScript/issues/50444"}

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:57137baa-98d0-da7a-c65a-d533aa12d7dc
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id928C:3F4253:27B2D47:34E4BA3:6B01B129
html-safe-noncee2622af28bb20890625e5994f05e041ed6ab00dab9137131a70644388511becf
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MjhDOjNGNDI1MzoyN0IyRDQ3OjM0RTRCQTM6NkIwMUIxMjkiLCJ2aXNpdG9yX2lkIjoiOTE5Njg0MjgyODgyMTU0MTE2MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac9dbf7f8d01819a6d69409fc10352e930e7acd7e0a3fa5a9954a41cd68a3ab0e3
hovercard-subject-tagissue:1350878660
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/50444/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ec315f46a0f0550d47ca7794b303abceee07381088df19edecb898f9eb5e09f2/microsoft/TypeScript/issues/50444
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ec315f46a0f0550d47ca7794b303abceee07381088df19edecb898f9eb5e09f2/microsoft/TypeScript/issues/50444
og:image:altBug Report I'm not exactly sure if this is a bug or not - CFA rules are not well-documented. I find the present behavior to be quite annoying though 🔎 Search Terms narrowing, control flow analysis,...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameAndarist
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/50444#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F50444
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%2F50444
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/50444
Reloadhttps://github.com/microsoft/TypeScript/issues/50444
Reloadhttps://github.com/microsoft/TypeScript/issues/50444
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/50444
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/50444
Control flow analysis overriding an explicit type declaration when the type flows from optional chaininghttps://github.com/microsoft/TypeScript/issues/50444#top
Not a DefectThis behavior is one of several equally-correct optionshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Not%20a%20Defect%22
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issue-1350878660
https://github.com/MartinJohns
Martin Johns (MartinJohns)https://github.com/MartinJohns
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1227382170
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1227451458
https://github.com/MartinJohns
Martin Johns (MartinJohns)https://github.com/MartinJohns
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1227455359
#47920https://github.com/microsoft/TypeScript/issues/47920
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1227464094
https://github.com/fatcerberus
Bruce Pascoe (fatcerberus)https://github.com/fatcerberus
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1227546425
https://github.com/Andarist
Mateusz Burzyński (Andarist)https://github.com/Andarist
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1227652208
https://github.com/MartinJohns
Martin Johns (MartinJohns)https://github.com/MartinJohns
on Aug 25, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1227691269
#50002https://github.com/microsoft/TypeScript/issues/50002
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Not a DefectThis behavior is one of several equally-correct optionshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Not%20a%20Defect%22
on Aug 26, 2022https://github.com/microsoft/TypeScript/issues/50444#event-7270457822
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 26, 2022https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1228953911
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Jun 8, 2023https://github.com/microsoft/TypeScript/issues/50444#issuecomment-1581847708
github-actionshttps://github.com/apps/github-actions
not plannedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Anot-planned
on Jun 8, 2023https://github.com/microsoft/TypeScript/issues/50444#event-9467150163
microsofthttps://github.com/microsoft
on Oct 22, 2025https://github.com/microsoft/TypeScript/issues/50444#event-20417588104
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/50444
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/50444
Not a DefectThis behavior is one of several equally-correct optionshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Not%20a%20Defect%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.