René's URL Explorer Experiment


Title: Regression in conditional type predicate · Issue #51242 · microsoft/TypeScript · GitHub

Open Graph Title: Regression in conditional type predicate · Issue #51242 · microsoft/TypeScript

X Title: Regression in conditional type predicate · Issue #51242 · microsoft/TypeScript

Description: Bug Report Search Terms: type assertion, type comparison, related to, generic parameter Version & Regression Information: This changed between versions 4.7 and 4.8 Code: Playground Link I discovered this issue in my PR #50454 when I am l...

Open Graph Description: Bug Report Search Terms: type assertion, type comparison, related to, generic parameter Version & Regression Information: This changed between versions 4.7 and 4.8 Code: Playground Link I discovere...

X Description: Bug Report Search Terms: type assertion, type comparison, related to, generic parameter Version & Regression Information: This changed between versions 4.7 and 4.8 Code: Playground Link I disco...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Regression in conditional type predicate ","articleBody":"## Bug Report\r\n\r\n**Search Terms:** type assertion, type comparison, related to, generic parameter\r\n\r\n**Version & Regression Information:** This changed between versions 4.7 and 4.8\r\n\r\n**Code:** [Playground Link](https://www.typescriptlang.org/play?ts=4.9.0-dev.20221020#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIAYAeAFQD4AKWAcwC54SBKem+LAZ3gFEAPDGKJlIAaeHCjA8EAJ7woqaQG0AumQDcAKFCRYCFOmx4kARlKUa9JixjU2nXv0EYRchSvVbw0OEjSZc+IgATGZUNpbMcjZ28ADeAL7wIHwgqMCcJPAA-AzwAGSuSsrw9A4CQiSi4pKoMoXumtreen6GgQDMoRYMkawccYnJGKnpuTmZBfJFJdx85c6V9aqNXrq+BgFIACxd4T3Wtv2ZQyOcU9kDSSlpGRcTSzNlTi7VUrJT7jOoIABuIDArHQ+fT+IyIACsuzo+yih1uJxuhQuCSuw0RmXG+QepTmz0WH1UX1+-0BzXWoMCADYoREDjFjtdRucck8KlUQBI3ksyES-gDPECWhswQB2GkwvrwxlnBQXVkLUQEnn0b580lrEFtJAADnFVlh9NRpzEHJqdQJd15JIFZM1m0QAE49b1okcjYiLZiVcT+U0Na17VBnXT+iiEaMMblJm5ipZ3aNXrV3jHLd61Tb-cLAgAjYMG0ODaVjKPY3LhmXTL3wVXWv3AgNgsB5yVlovMy7l4v3C1xzuJ80pqs1mBW32retZpDAZuuqVopmynJhouR7sp3ttwe5NP-UfqicUpAgGdw1vziuWvumrme7fVn17jMHrWIRAnw2d9sM88PIcPnf8hodpGGAUDsCApjfsaUzmHGAA+DAqJEJAqHEGgAJBwBgyAwIEVCMBcUAzIoUDKJo8RAQ2+CgeBIRQYiaAANaoDgADuqCwbkCEocoyGobEGFYTheFQAROREfQJFkRoFHAdRYEgJ05BUPBiG8ZY-GCSA2G4Ug+GEcRpHkRoQA)\r\n\r\nI discovered this issue in my PR #50454 when I am looking for a possible solution to the typing of `Array.isArray`.\r\nConsider the following code:\r\n\r\n```ts\r\ndeclare function f0\u003cT>(arg: T): arg is Extract\u003cT, readonly any[]>;\r\ndeclare function f1\u003cT>(arg: T): arg is Extract\u003cT, any[]>;\r\ndeclare function f2\u003cT>(arg: T): arg is {} extends T ? T & any[] : Extract\u003cT, readonly any[]>;\r\ndeclare function f3\u003cT>(arg: T): arg is {} extends T ? T & any[] : Extract\u003cT, any[]>;\r\ndeclare function f4\u003cT>(arg: T): arg is T extends any ? {} extends T ? T & any[] : Extract\u003cT, readonly any[]> : never;\r\ndeclare function f5\u003cT>(arg: T): arg is T extends any ? {} extends T ? T & any[] : Extract\u003cT, any[]> : never;\r\ndeclare function f6\u003cT>(arg: T): arg is T extends any ? Extract\u003cT, readonly any[]> : never;\r\ndeclare function f7\u003cT>(arg: T): arg is T extends any ? Extract\u003cT, any[]> : never;\r\ndeclare function f8\u003cT>(arg: T): arg is T extends readonly any[] ? T : never;\r\ndeclare function f9\u003cT>(arg: T): arg is T extends any[] ? T : never;\r\ndeclare function fa\u003cT>(arg: T): arg is {} extends T ? T & any[] : T extends readonly any[] ? T : never;\r\ndeclare function fb\u003cT>(arg: T): arg is {} extends T ? T & any[] : T extends any[] ? T : never;\r\ndeclare function fc\u003cT>(arg: T): arg is T extends any ? {} extends T ? T & any[] : T extends readonly any[] ? T : never : never;\r\ndeclare function fd\u003cT>(arg: T): arg is T extends any ? {} extends T ? T & any[] : T extends any[] ? T : never : never;\r\ndeclare function fe\u003cT>(arg: T): arg is T extends any ? T extends readonly any[] ? T : never : never;\r\ndeclare function ff\u003cT>(arg: T): arg is T extends any ? T extends any[] ? T : never : never;\r\n\r\nfunction case1\u003cT extends any>(a: T | T[]): T[] {\r\n\treturn f(a) ? a : [a];\r\n}\r\nfunction case2\u003cT extends unknown>(a: T | T[]): T[] {\r\n\treturn f(a) ? a : [a];\r\n}\r\nfunction case3\u003cT>(a: T | T[]): T[] {\r\n\treturn f(a) ? a : [a];\r\n}\r\n```\r\n\r\nIn the above, `f4` is the simplified version of the type I used in the PR.\r\n\r\n**Actual behavior:**\r\n\r\nFrom 4.8, the results vary from function to function. In case 3, an error occurs when `f` is `f4` but not in case 1 and case 2 or the case when `f` is `f2` where `T` is not distributed using `T extends any`.\r\nHere is a table of whether a ts2322 error occurs in each cases:\r\n\r\n| f | Case 1 | Case 2 | Case 3 |\r\n|:---:|:---:|:---:|:---:|\r\n| f0 | 🛑 | 🛑 | 🛑 |\r\n| f1 | ⚪ | ⚪ | ⚪ |\r\n| f2 | ⚪ | ⚪ | ⚪ |\r\n| f3 | ⚪ | ⚪ | ⚪ |\r\n| f4 | ⚪ | ⚪ | 🛑 |\r\n| f5 | ⚪ | ⚪ | ⚪ |\r\n| f6 | 🛑 | 🛑 | 🛑 |\r\n| f7 | ⚪ | ⚪ | ⚪ |\r\n\r\nFor the latter half, `f(n+8)` is simply `fn` with `Extract` expanded out, but I could hardly understand why the behavior changes:\r\n\r\n| f | Case 1 | Case 2 | Case 3 |\r\n|:---:|:---:|:---:|:---:|\r\n| f8 | 🛑 | 🛑 | 🛑 |\r\n| f9 | ⚪ | ⚪ | ⚪ |\r\n| fa | ⚪ | ⚪ | ⚪ |\r\n| fb | ⚪ | ⚪ | ⚪ |\r\n| fc | ⚪ | ⚪ | 🛑 |\r\n| fd | ⚪ | ⚪ | 🛑 |\r\n| fe | 🛑 | 🛑 | 🛑 |\r\n| ff | 🛑 | 🛑 | 🛑 |\r\n\r\n(Tested in v4.9.0-dev.20221020 and 4.8.4)\r\n\r\nPrior to 4.8, ALL the cases passed:\r\n\r\n| f | Case 1 | Case 2 | Case 3 |\r\n|:---:|:---:|:---:|:---:|\r\n| f0 | ⚪ | ⚪ | ⚪ |\r\n| f1 | ⚪ | ⚪ | ⚪ |\r\n| f2 | ⚪ | ⚪ | ⚪ |\r\n| f3 | ⚪ | ⚪ | ⚪ |\r\n| f4 | ⚪ | ⚪ | ⚪ |\r\n| f5 | ⚪ | ⚪ | ⚪ |\r\n| f6 | ⚪ | ⚪ | ⚪ |\r\n| f7 | ⚪ | ⚪ | ⚪ |\r\n| f8 | ⚪ | ⚪ | ⚪ |\r\n| f9 | ⚪ | ⚪ | ⚪ |\r\n| fa | ⚪ | ⚪ | ⚪ |\r\n| fb | ⚪ | ⚪ | ⚪ |\r\n| fc | ⚪ | ⚪ | ⚪ |\r\n| fd | ⚪ | ⚪ | ⚪ |\r\n| fe | ⚪ | ⚪ | ⚪ |\r\n| ff | ⚪ | ⚪ | ⚪ |\r\n\r\n(Tested in 4.7.4 and 4.6.4)\r\n\r\n(Note: some of the test functions above are for control (i.e. comparison) only.)\r\n\r\n**Expected behavior:**\r\n\r\nFor each row, the results of case 1, case 2 and case 3 should be identical. (`f4`, `fc`, `fd`)\r\nFor each column, the results of `fn` and `f(n+8)` should be identical. (`f5`, `fd`, `f7`, `ff`)\r\n\r\nI understand that some of them must be desirable changes, so I am not expecting the results to be the same between 4.7 and 4.8, but the mismatched results due to the absent of generic constraint are really weird.","author":{"url":"https://github.com/graphemecluster","@type":"Person","name":"graphemecluster"},"datePublished":"2022-10-20T18:50:22Z","url":"https://github.com/microsoft/TypeScript/issues/51242"}

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:fb2e4df8-686f-452f-2bde-01a8f02ebec8
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idB5B0:16EED3:306C77C:3DB51FE:6B01CE17
html-safe-nonceabfd4d6bfec4d41907d19a053442cb0fb7b143d2046a5bb55c3535d082d7ca0e
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNUIwOjE2RUVEMzozMDZDNzdDOjNEQjUxRkU6NkIwMUNFMTciLCJ2aXNpdG9yX2lkIjoiMjA5NDQ3MzExNDcyODY0ODIxNSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacb18799eaf557c632f0909a733f5203986950178027fa5afa8ba34b497e9a3daf
hovercard-subject-tagissue:1417099025
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/51242/issue_layout
twitter:imagehttps://opengraph.githubassets.com/ff120a84c4862084c6a88b5e9f916ae2a53fecf0cc53b703017fab7b4d040e55/microsoft/TypeScript/issues/51242
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/ff120a84c4862084c6a88b5e9f916ae2a53fecf0cc53b703017fab7b4d040e55/microsoft/TypeScript/issues/51242
og:image:altBug Report Search Terms: type assertion, type comparison, related to, generic parameter Version & Regression Information: This changed between versions 4.7 and 4.8 Code: Playground Link I discovere...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamegraphemecluster
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/51242#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F51242
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%2F51242
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/51242
Reloadhttps://github.com/microsoft/TypeScript/issues/51242
Reloadhttps://github.com/microsoft/TypeScript/issues/51242
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/51242
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/51242
Regression in conditional type predicate https://github.com/microsoft/TypeScript/issues/51242#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/graphemecluster
graphemecluster (graphemecluster)https://github.com/graphemecluster
on Oct 20, 2022https://github.com/microsoft/TypeScript/issues/51242#issue-1417099025
Playground Linkhttps://www.typescriptlang.org/play?ts=4.9.0-dev.20221020#code/CYUwxgNghgTiAEAzArgOzAFwJYHtVIAYAeAFQD4AKWAcwC54SBKem+LAZ3gFEAPDGKJlIAaeHCjA8EAJ7woqaQG0AumQDcAKFCRYCFOmx4kARlKUa9JixjU2nXv0EYRchSvVbw0OEjSZc+IgATGZUNpbMcjZ28ADeAL7wIHwgqMCcJPAA-AzwAGSuSsrw9A4CQiSi4pKoMoXumtreen6GgQDMoRYMkawccYnJGKnpuTmZBfJFJdx85c6V9aqNXrq+BgFIACxd4T3Wtv2ZQyOcU9kDSSlpGRcTSzNlTi7VUrJT7jOoIABuIDArHQ+fT+IyIACsuzo+yih1uJxuhQuCSuw0RmXG+QepTmz0WH1UX1+-0BzXWoMCADYoREDjFjtdRucck8KlUQBI3ksyES-gDPECWhswQB2GkwvrwxlnBQXVkLUQEnn0b580lrEFtJAADnFVlh9NRpzEHJqdQJd15JIFZM1m0QAE49b1okcjYiLZiVcT+U0Na17VBnXT+iiEaMMblJm5ipZ3aNXrV3jHLd61Tb-cLAgAjYMG0ODaVjKPY3LhmXTL3wVXWv3AgNgsB5yVlovMy7l4v3C1xzuJ80pqs1mBW32retZpDAZuuqVopmynJhouR7sp3ttwe5NP-UfqicUpAgGdw1vziuWvumrme7fVn17jMHrWIRAnw2d9sM88PIcPnf8hodpGGAUDsCApjfsaUzmHGAA+DAqJEJAqHEGgAJBwBgyAwIEVCMBcUAzIoUDKJo8RAQ2+CgeBIRQYiaAANaoDgADuqCwbkCEocoyGobEGFYTheFQAROREfQJFkRoFHAdRYEgJ05BUPBiG8ZY-GCSA2G4Ug+GEcRpHkRoQA
#50454https://github.com/microsoft/TypeScript/pull/50454
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 20, 2022https://github.com/microsoft/TypeScript/issues/51242#issuecomment-1286248837
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 20, 2022https://github.com/microsoft/TypeScript/issues/51242#issuecomment-1286256239
https://github.com/typescript-bot
TypeScript Bot (typescript-bot)https://github.com/typescript-bot
on Oct 20, 2022https://github.com/microsoft/TypeScript/issues/51242#issuecomment-1286260111
2c68dedhttps://github.com/microsoft/TypeScript/commit/2c68ded95498dc637acdb00e8349f51832f5a6df
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 Oct 27, 2022https://github.com/microsoft/TypeScript/issues/51242#event-7686248878
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Oct 27, 2022https://github.com/microsoft/TypeScript/issues/51242#issuecomment-1294185689
https://github.com/graphemecluster
graphemecluster (graphemecluster)https://github.com/graphemecluster
on Oct 28, 2022https://github.com/microsoft/TypeScript/issues/51242#issuecomment-1294541429
Ryan Cavanaugh (@RyanCavanaugh)https://github.com/RyanCavanaugh
#50454https://github.com/microsoft/TypeScript/pull/50454
https://github.com/apps/github-actions
github-actionshttps://github.com/apps/github-actions
on Jun 8, 2023https://github.com/microsoft/TypeScript/issues/51242#issuecomment-1581847531
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/51242#event-9467148446
microsofthttps://github.com/microsoft
on Oct 22, 2025https://github.com/microsoft/TypeScript/issues/51242#event-20417617819
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/51242
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/51242
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.