René's URL Explorer Experiment


Title: Optional chaining, proper infer in type guard · Issue #34974 · microsoft/TypeScript · GitHub

Open Graph Title: Optional chaining, proper infer in type guard · Issue #34974 · microsoft/TypeScript

X Title: Optional chaining, proper infer in type guard · Issue #34974 · microsoft/TypeScript

Description: TypeScript Version: 3.7.0 Search Terms: optional chaining Code type X = { y?: { z?: string } } const x: X = { y: { } } // type guard function isNotNull(x: A): x is NonNullable { return x!== null && x!== undefined; } // function whi...

Open Graph Description: TypeScript Version: 3.7.0 Search Terms: optional chaining Code type X = { y?: { z?: string } } const x: X = { y: { } } // type guard function isNotNull(x: A): x is NonNullable { return x!== n...

X Description: TypeScript Version: 3.7.0 Search Terms: optional chaining Code type X = { y?: { z?: string } } const x: X = { y: { } } // type guard function isNotNull<A>(x: A): x is NonNullable<A> { r...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Optional chaining, proper infer in type guard","articleBody":"**TypeScript Version:**  3.7.0\r\n\r\n**Search Terms:** optional chaining\r\n\r\n**Code**\r\n\r\n```ts\r\ntype X = {\r\n  y?: {\r\n    z?: string\r\n  }\r\n}\r\nconst x: X = {\r\n  y: {\r\n  }\r\n}\r\n// type guard\r\nfunction isNotNull\u003cA>(x: A): x is NonNullable\u003cA> {\r\n  return x!== null && x!== undefined;\r\n}\r\n// function which I want to call in the result of the expression\r\nfunction title(str: string) {\r\n  return str.length > 0 ? 'Dear ' + str : 'Dear nobody';\r\n}\r\n\r\nisNotNull(x?.y?.z) ? title(x.y.z) : null // type error - object is possibly undefined\r\n```\r\nThe code fix is by adding additional checks or additional temporary variables:\r\n```ts\r\n(x?.y?.z && isNotNull(x.y.z)) ? title(x.y.z) : null\r\n// or\r\nconst tmp = x?.y?.z\r\nisNotNull(tmp) ? title(tmp) : null\r\n```\r\n**Expected behavior:**\r\nTypeScript is able to infer that optional chaining was used as an argument, what means that typeguard is checking the whole chain.\r\n\r\n**Actual behavior:**\r\nTypeScript needs a code change in order to understand that optional chaining already checked other values from being null | undefined.\r\n","author":{"url":"https://github.com/maciejsikora","@type":"Person","name":"maciejsikora"},"datePublished":"2019-11-07T13:10:33Z","url":"https://github.com/microsoft/TypeScript/issues/34974"}

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:75c7094a-95d8-c541-9d66-ff1ee0d0f99c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAEB8:3FEC83:216460:2BA997:6B016702
html-safe-nonce94d3b24bb29bebacf9ab400a8c1d9e757fff98df0879ceb37f1de34ba3eebbd7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRUI4OjNGRUM4MzoyMTY0NjA6MkJBOTk3OjZCMDE2NzAyIiwidmlzaXRvcl9pZCI6IjYxMTIzOTM4Njc0MjI2ODkwMjYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac01b81e2acc78a56824d6c7a10932d629367fa09582d3ec6417b15063e2224768
hovercard-subject-tagissue:519257090
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/34974/issue_layout
twitter:imagehttps://opengraph.githubassets.com/300ae9e9e84e281ff31b9541c38a7c1e34843db7ef57333fb09c39bdcd62e8cd/microsoft/TypeScript/issues/34974
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/300ae9e9e84e281ff31b9541c38a7c1e34843db7ef57333fb09c39bdcd62e8cd/microsoft/TypeScript/issues/34974
og:image:altTypeScript Version: 3.7.0 Search Terms: optional chaining Code type X = { y?: { z?: string } } const x: X = { y: { } } // type guard function isNotNull(x: A): x is NonNullable { return x!== n...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemaciejsikora
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/34974#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F34974
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%2F34974
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/34974
Reloadhttps://github.com/microsoft/TypeScript/issues/34974
Reloadhttps://github.com/microsoft/TypeScript/issues/34974
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/34974
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/34974
#55613https://github.com/microsoft/TypeScript/pull/55613
Optional chaining, proper infer in type guardhttps://github.com/microsoft/TypeScript/issues/34974#top
#55613https://github.com/microsoft/TypeScript/pull/55613
Experience EnhancementNoncontroversial enhancementshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Experience%20Enhancement%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
Backloghttps://github.com/microsoft/TypeScript/milestone/29
https://github.com/maciejsikora
Maciej Sikora (maciejsikora)https://github.com/maciejsikora
on Nov 7, 2019https://github.com/microsoft/TypeScript/issues/34974#issue-519257090
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 Nov 8, 2019https://github.com/microsoft/TypeScript/issues/34974#event-2784621226
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Nov 8, 2019https://github.com/microsoft/TypeScript/issues/34974#issuecomment-551999684
https://github.com/MartinEneqvistRegionSkane
Martin Eneqvist (MartinEneqvistRegionSkane)https://github.com/MartinEneqvistRegionSkane
on Jun 3, 2021https://github.com/microsoft/TypeScript/issues/34974#issuecomment-853688286
https://github.com/lo1tuma
Mathias Schreck (lo1tuma)https://github.com/lo1tuma
on Sep 27, 2021https://github.com/microsoft/TypeScript/issues/34974#issuecomment-927799755
Song Gao (@ShuiRuTian)https://github.com/ShuiRuTian
#38839https://github.com/microsoft/TypeScript/pull/38839
https://github.com/ShuiRuTian
Song Gao (ShuiRuTian)https://github.com/ShuiRuTian
on Sep 28, 2021https://github.com/microsoft/TypeScript/issues/34974#issuecomment-928893967
Mathias Schreck (@lo1tuma)https://github.com/lo1tuma
https://github.com/stabai
Shawn Tabai (stabai)https://github.com/stabai
on Jul 10, 2022https://github.com/microsoft/TypeScript/issues/34974#issuecomment-1179815042
Here is a playground linkhttps://www.typescriptlang.org/play?ts=4.7.4#code/JYOwLgpgTgZghgYwgAgIImAWzgG2QbwChkTkAjKCCAEwH4AuZAIUpoG5CBfQ0SWRFCyrUCxUgGdgALwgNk4sFFABzDt0IwAriARhgAexDJg4gHLAcACgBuuTREbaA1iH0B3EAEpGtnPePiyNrUEDCgNAA+IJo4eESkyJRgmlBGvv4AvBnI0bFqhBraugZGyhBgQjQAytIQAOrAYAAW+ppgAGJFeoaWcBjYOIzoWLje8ooqEcGh4SLxpMAwyL39uLQAdBTCG5IyyACE2bk4nqIJCUkpRn0jOJus1Ou7EBwJnMgQOOIo8+eJ5VcgiAQmEQOwxCRuOotDpuqVypVqDUZA1mp1YSUVrchqsTowFEoQMopsCZmC5hDjEtLPsTOYrDcBhstjQdrVPKdfudLqlkIzcPdhE9aq9SO9Pt8zn9-sledNQeC3lxCEA
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Experience EnhancementNoncontroversial enhancementshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Experience%20Enhancement%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 Aug 31, 2022https://github.com/microsoft/TypeScript/issues/34974#event-7298807188
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Backloghttps://github.com/microsoft/TypeScript/milestone/29
on Aug 31, 2022https://github.com/microsoft/TypeScript/issues/34974#event-7298807350
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Aug 31, 2022https://github.com/microsoft/TypeScript/issues/34974#issuecomment-1233285635
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Help Wantedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Help%20Wanted%22
on Aug 31, 2022https://github.com/microsoft/TypeScript/issues/34974#event-7298809946
https://github.com/kbrilla
Krzysztof Brilla (kbrilla)https://github.com/kbrilla
on Oct 16, 2022https://github.com/microsoft/TypeScript/issues/34974#issuecomment-1280004088
playgroundhttps://www.typescriptlang.org/play?ts=4.7.4#code/JYOwLgpgTgZghgYwgAgIImAWzgG2QbwChkTkAjKCCAEwH4AuZAIUpoG5CBfQ0SWRFCyrUCxUgGdgALwgNk4sFFABzDt0IwAriARhgAexDJg4gHLAcACgBuuTREbaA1iH0B3EAEpGtnPePiyNrUEDCgNAA+IJo4eESkyJRgmlBGvv4AvBnI0bFqhBraugZGyhBgQjQAytIQAOrAYAAW+ppgAGJFeoaWcBjYOIzoWLje8ooqEcGh4SLxpMAwyL39uLQAdBTCG5IyyACE2bk4nqIJCUkpRn0jOJus1Ou7EBwJnMgQOOIo8+eJ5VcgiAQmEQOwxCRuOotDpuqVypVqDUZA1mp1YSUVrchqsTowFEoQMopsCZmC5hDjEtLPsTOYrDcBhstjQdrVPKdfudLqlkIzcPdhE9aq9SO9Pt8zn9-sledNQeC3lwCoUMYZkGUKg9kfVGk0ACoQEBwKAATyxAxxtzGBMm8tmUpIi2W-LwtD5uMFNGQ7tdXsez2QjlJCpEwZBs05lIuAN5fpZAZFlPFXx+0dIPKM9vJoshXCAA
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
Wesley Wigham (weswigham)https://github.com/weswigham
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#55613https://github.com/microsoft/TypeScript/pull/55613
on Sep 13, 2023https://github.com/microsoft/TypeScript/issues/34974#event-10363012781
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/34974
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/34974
Experience EnhancementNoncontroversial enhancementshttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Experience%20Enhancement%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
BacklogNo due datehttps://github.com/microsoft/TypeScript/milestone/29
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.