René's URL Explorer Experiment


Title: Previous generic union does not narrow to an union again with type predicate · Issue #38869 · microsoft/TypeScript · GitHub

Open Graph Title: Previous generic union does not narrow to an union again with type predicate · Issue #38869 · microsoft/TypeScript

X Title: Previous generic union does not narrow to an union again with type predicate · Issue #38869 · microsoft/TypeScript

Description: TypeScript Version: 4.0.0-dev.20200531 Search Terms: type narrow discriminant generic Code interface A { t: true; v: T[K]; } interface B { t: false; e: Error; } type X = A | B; type Some = { y: number...

Open Graph Description: TypeScript Version: 4.0.0-dev.20200531 Search Terms: type narrow discriminant generic Code interface A { t: true; v: T[K]; } interface B { t: false; e: Error; } type X = A<...

X Description: TypeScript Version: 4.0.0-dev.20200531 Search Terms: type narrow discriminant generic Code interface A<T, K extends keyof T> { t: true; v: T[K]; } interface B { t: false; e: Error; } type X&l...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Previous generic union does not narrow to an union again with type predicate","articleBody":"\u003c!--\r\nPlease try to reproduce the issue with the latest published version. It may have already been fixed.\r\nFor npm: `typescript@next`\r\nThis is also the 'Nightly' version in the playground: http://www.typescriptlang.org/play/?ts=Nightly\r\n-->\r\n**TypeScript Version:**  4.0.0-dev.20200531\r\n\r\n\u003c!-- Search terms you tried before logging this (so others can find this issue more easily) -->\r\n**Search Terms:** type narrow discriminant generic\r\n\r\n**Code**\r\n\r\n```ts\r\ninterface A\u003cT, K extends keyof T> {\r\n    t: true;\r\n    v: T[K];\r\n}\r\ninterface B {\r\n    t: false;\r\n    e: Error;\r\n}\r\ntype X\u003cT> = A\u003cT, keyof T> | B;\r\n\r\ntype Some = { y: number; z: string };\r\ndeclare function assertIsX(x: unknown): asserts x is X\u003cSome>;\r\n\r\n// CASE 1: narrowing unknown (works)\r\ndeclare const some: unknown;\r\nassertIsX(some);\r\n// Ok, `r1` is `string | number | Error` as expected\r\nconst r1 = some.t ? some.v : some.e;\r\n\r\n// CASE 2: before narrowing (works)\r\ndeclare const some2: X\u003c{ [k: string]: unknown }>;\r\n// Ok, `r2` is `unknown` as expected\r\nconst r2 = some2.t ? some2.v : some2.e;\r\n\r\n// CASE 3: narrowing again (does not work)\r\nassertIsX(some2);\r\n// ERROR: `some2` narrowed to `B`, not `X\u003cSome>`,\r\n// so `v` isn't accesible\r\nsome2.t ? some2.v : some2.e;\r\n\r\n// CASE 4: narrowing `A\u003cany, any> | B` (does not work)\r\ndeclare function onlyASomeHere(x: A\u003cSome, keyof Some>): void;\r\ndeclare const a: A\u003cany, any>;\r\n// `A\u003cany, any>` is assignable to `A\u003cSome, keyof Some>`\r\nonlyASomeHere(a);\r\n\r\ndeclare const some3: A\u003cany, any> | B;\r\nassertIsX(some3);\r\n// ERROR: `some3` narrowed to `B`, not `X\u003cSome>`\r\nsome3.t ? some3.v : some3.e;\r\n```\r\nI'm using a type assertion, but a type predicate makes no difference. The same happens starting with `X\u003cany>` or `X\u003cunknown>`.\r\n\r\n**Expected behavior:** `some2` is narrowed to the union `A\u003cSome> | B` so `.v` can be accessed when `t === true`.\r\n\r\n**Actual behavior:** `some2` narrows only to `B`, so when `t === true` `some2` is `never`.\r\n\r\n**Playground Link:** [playground](https://www.typescriptlang.org/play/index.html?ts=4.0.0-dev.20200531&ssl=31&ssc=22&pln=31&pc=39#code/JYOwLgpgTgZghgYwgAgIIB4AqAaZBpZCAD0hABMBnZAawgE8B7GZTAPmQG8AoZX5MAFz8oAVwgBuHnwBuQzAG08AXUkBfLqEixEKAEKcpvQcngAbChMOEhAUShQGUNVzB0ADigAaWdgF40WLi0jMxsyAA+yLqSLu4oAMoMALYo-hzIdEIgIkkARtDiyABeQhRgUKAA5siqkmQQCKZwUCgwIiAIYMAMIMhwFBZQYACSFJ4AFERC7dQgDADuIACUQv2DYFREyMBU3okprDEA9EfIAMKo8TbIAIxZzQ7zVcgzc4vI4-OO1BRLXPWNZooBA9MrICjJCDTECzBYgSRraAjMbjCEpJaSE7IADy1FwAAMoDd8dsqPiyhUQNVItk8tAIsg7A4oCT+oQiB5OhAyFwQSAwUTkP40RAAHRgZAAfnBkNF0mQpVlli4WIuV2QACYhPkYI4UCAHgtnp9vr9-g0mi1kHywSKtchvOl5NRSuUqkpobD3qpDirTriCVANSSdsh8a84ayqMROZAeTaJUGhTKUhrxVKUxA0-LFanRcrVZdrgBme72I1UvqVOCgD5kBgQKhzCVfKDUP6IoajCZ2jF+xkAJQH2IHQnJkODyAN5fm3P4DDDunxuGbYb2kNYy-7ELD0hDFBAAHIJYgkBRgLlTBAuHb09LbznM2mC6c1dcACxlx7PfEYOAgOhcH-Oh2EiJc6wbJsGBbb4-gBS1WnaTpul6HpTDoS5IQACWgCBJiEDB9ggIJ6CYZAiNYFZkGkBhgDIOoLSBa1QRPAj0GAoCAN9LFf3YgDOJA-c+gGYBKgNS8UDABdeKIkiQnIjd8S4NCMKInCWnGOA+3NQErQTTNSwCDi+i4hloi4TtkR7SFiz7LEbCHEcxxFYsSWnR45ykxdlynaC13QCilJcu8DLlBVQssIA)\r\n\r\n**Related Issues:** Maybe #30557 but that case works on last nightly and this does not.\r\n","author":{"url":"https://github.com/InExtremaRes","@type":"Person","name":"InExtremaRes"},"datePublished":"2020-06-01T00:42:12Z","url":"https://github.com/microsoft/TypeScript/issues/38869"}

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:80baa2a2-bed8-2927-5dea-544f5b447a6c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id9074:2D96F1:CD3CCB:110FBEE:6B00F7B9
html-safe-nonce6e359f96cfe8c9d35f2600a8944964c8670e29f08d9584eb3152957c15050186
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MDc0OjJEOTZGMTpDRDNDQ0I6MTEwRkJFRTo2QjAwRjdCOSIsInZpc2l0b3JfaWQiOiIxNTUyMjQxMzkyMDUzNDUwNjgxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac9ae9e478a0faaa2375bd46c623f478a57a53af8c6f3861394be8a788bde94a7c
hovercard-subject-tagissue:628081422
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/38869/issue_layout
twitter:imagehttps://opengraph.githubassets.com/2ae9f8060c64b6cee390adbd95be1284775ee70aa681c42a8145e6f596b12f1e/microsoft/TypeScript/issues/38869
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/2ae9f8060c64b6cee390adbd95be1284775ee70aa681c42a8145e6f596b12f1e/microsoft/TypeScript/issues/38869
og:image:altTypeScript Version: 4.0.0-dev.20200531 Search Terms: type narrow discriminant generic Code interface A { t: true; v: T[K]; } interface B { t: false; e: Error; } type X = A<...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameInExtremaRes
hostnamegithub.com
expected-hostnamegithub.com
Nonee208d86428ec00a57ade75058166297440e8128a01e5287c31a53dc042bbf187
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
release7dafd017fb7809a839c443dba08622af38e63c09
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/38869#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F38869
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%2F38869
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/38869
Reloadhttps://github.com/microsoft/TypeScript/issues/38869
Reloadhttps://github.com/microsoft/TypeScript/issues/38869
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/38869
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/38869
#49625https://github.com/microsoft/TypeScript/pull/49625
Previous generic union does not narrow to an union again with type predicatehttps://github.com/microsoft/TypeScript/issues/38869#top
#49625https://github.com/microsoft/TypeScript/pull/49625
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
https://github.com/InExtremaRes
Daniel Contreras (InExtremaRes)https://github.com/InExtremaRes
on Jun 1, 2020https://github.com/microsoft/TypeScript/issues/38869#issue-628081422
playgroundhttps://www.typescriptlang.org/play/index.html?ts=4.0.0-dev.20200531&ssl=31&ssc=22&pln=31&pc=39#code/JYOwLgpgTgZghgYwgAgIIB4AqAaZBpZCAD0hABMBnZAawgE8B7GZTAPmQG8AoZX5MAFz8oAVwgBuHnwBuQzAG08AXUkBfLqEixEKAEKcpvQcngAbChMOEhAUShQGUNVzB0ADigAaWdgF40WLi0jMxsyAA+yLqSLu4oAMoMALYo-hzIdEIgIkkARtDiyABeQhRgUKAA5siqkmQQCKZwUCgwIiAIYMAMIMhwFBZQYACSFJ4AFERC7dQgDADuIACUQv2DYFREyMBU3okprDEA9EfIAMKo8TbIAIxZzQ7zVcgzc4vI4-OO1BRLXPWNZooBA9MrICjJCDTECzBYgSRraAjMbjCEpJaSE7IADy1FwAAMoDd8dsqPiyhUQNVItk8tAIsg7A4oCT+oQiB5OhAyFwQSAwUTkP40RAAHRgZAAfnBkNF0mQpVlli4WIuV2QACYhPkYI4UCAHgtnp9vr9-g0mi1kHywSKtchvOl5NRSuUqkpobD3qpDirTriCVANSSdsh8a84ayqMROZAeTaJUGhTKUhrxVKUxA0-LFanRcrVZdrgBme72I1UvqVOCgD5kBgQKhzCVfKDUP6IoajCZ2jF+xkAJQH2IHQnJkODyAN5fm3P4DDDunxuGbYb2kNYy-7ELD0hDFBAAHIJYgkBRgLlTBAuHb09LbznM2mC6c1dcACxlx7PfEYOAgOhcH-Oh2EiJc6wbJsGBbb4-gBS1WnaTpul6HpTDoS5IQACWgCBJiEDB9ggIJ6CYZAiNYFZkGkBhgDIOoLSBa1QRPAj0GAoCAN9LFf3YgDOJA-c+gGYBKgNS8UDABdeKIkiQnIjd8S4NCMKInCWnGOA+3NQErQTTNSwCDi+i4hloi4TtkR7SFiz7LEbCHEcxxFYsSWnR45ykxdlynaC13QCilJcu8DLlBVQssIA
#30557https://github.com/microsoft/TypeScript/issues/30557
https://github.com/jack-williams
Jack Williams (jack-williams)https://github.com/jack-williams
on Jun 1, 2020https://github.com/microsoft/TypeScript/issues/38869#issuecomment-636914049
#31156https://github.com/microsoft/TypeScript/issues/31156
https://github.com/InExtremaRes
Daniel Contreras (InExtremaRes)https://github.com/InExtremaRes
on Jun 1, 2020https://github.com/microsoft/TypeScript/issues/38869#issuecomment-636955767
Jack Williams (@jack-williams)https://github.com/jack-williams
#32158https://github.com/microsoft/TypeScript/issues/32158
https://github.com/jack-williams
Jack Williams (jack-williams)https://github.com/jack-williams
on Jun 1, 2020https://github.com/microsoft/TypeScript/issues/38869#issuecomment-636967069
https://github.com/InExtremaRes
Daniel Contreras (InExtremaRes)https://github.com/InExtremaRes
on Jun 10, 2020https://github.com/microsoft/TypeScript/issues/38869#issuecomment-641656524
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
DuplicateAn existing issue was already createdhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Duplicate%22
on Jun 10, 2020https://github.com/microsoft/TypeScript/issues/38869#event-3430295603
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 Jun 12, 2020https://github.com/microsoft/TypeScript/issues/38869#event-3439427756
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Jun 12, 2020https://github.com/microsoft/TypeScript/issues/38869#issuecomment-643411535
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/38869#event-20416973420
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/38869
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/38869
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

Viewport: width=device-width


URLs of crawlers that visited me.