René's URL Explorer Experiment


Title: Generic with type inference in conditional type not evaluated into definitive type · Issue #42636 · microsoft/TypeScript · GitHub

Open Graph Title: Generic with type inference in conditional type not evaluated into definitive type · Issue #42636 · microsoft/TypeScript

X Title: Generic with type inference in conditional type not evaluated into definitive type · Issue #42636 · microsoft/TypeScript

Description: Bug Report 🔎 Search Terms generic conditional type inference not evaluated 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about generic and conditional types ⏯ Playgro...

Open Graph Description: Bug Report 🔎 Search Terms generic conditional type inference not evaluated 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about...

X Description: Bug Report 🔎 Search Terms generic conditional type inference not evaluated 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries a...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generic with type inference in conditional type not evaluated into definitive type","articleBody":"# Bug Report\r\n\r\n\u003c!--\r\n  Please fill in each section completely. Thank you!\r\n--\u003e\r\n\r\n### 🔎 Search Terms\r\n\r\ngeneric conditional type inference not evaluated\r\n\r\n### 🕗 Version \u0026 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: http://www.typescriptlang.org/play/?ts=Nightly\r\n\r\nNote: The TypeScript Playground can be used to try older versions of TypeScript.\r\n\r\nPlease keep and fill in the line that best applies:\r\n--\u003e\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about generic and conditional types\r\n\r\n### ⏯ Playground Link\r\n\r\n\u003c!--\r\n  A link to a TypeScript Playground \"Share\" link which shows this behavior\r\n\r\n  The TypeScript Workbench can be used for more complex setups, try\r\n  https://www.typescriptlang.org/dev/bug-workbench/\r\n\r\n  As a last resort, you can link to a repo, but these will be slower for us to investigate.\r\n--\u003e\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.1.3#code/C4TwDgpgBAygrgIwOJwIYCcAmAeAggGigA0oIAPYCAO0wGcoBtXAXQD4oBeYgbgChfQkKAEla8BNgCypCtTpRUVEA2aEYMyjXqLlbTlGnlN8hryhQAdFfEoMOSQypwAtggjpVUAJZUAZu6gAIVZ8M0trUPMrCx0VXmYwgH4gsIAuKCoIADd3PgFwaABRAAZ9UXFsBgBGQgAmQgBmQgAWTwZ6qCaoVtZuKAB6fvNCrNQAGzRKTHTBItKuarrGluYNOXoGaJ9-dCClzpbCaNjmVeTAqHTMnPR+WahCqv1FqA6u1rWtRi2-AMD995HKwnM5BS4ZbK5AZDe6PfRwKgAayoAHsAO5UOK8TAQADGYww0DGEGAUCyxXSJT4OPxhKgxNJWSqlKq1LxBPQRJJZNq6QRyPRmOYeXM5P0TPFtXFrN4gygAD0oAAVApQADk-NRGJUau89FRpNQtFoXgA5lRUAhiVBgCibaq1eVEJUaq9lt02m8Vqw1RYABS1Bq1WoASn4Eq4WSlkeKfTlAHlEbwgA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well--\u003e\r\n```ts\r\ntype SubGuard\u003cA, X extends [A]\u003e = X;\r\n\r\ntype IsSub\u003cM extends any[], S extends any[]\u003e = M extends [\r\n  ...SubGuard\u003cM[number], infer B\u003e,\r\n  ...S,\r\n  ...any[]\r\n]\r\n  ? B\r\n  : never;\r\n\r\ntype E0 = IsSub\u003c[1, 2, 3, 4], [2, 3, 4]\u003e; //  Evaluated: type E0 = [1, 2, 3, 4] extends [...infer B, 2, 3, 4, ...any[]] ? B : never\r\n\r\ntype E1 = [1, 2, 3, 4] extends [...infer B, 2, 3, 4, ...any[]] ? B : never; // type E1 = unknown[]\r\n\r\ndeclare let v0: E0;\r\ndeclare let v1: E1;\r\ndeclare let v2: unknown[];\r\n\r\n  v0 = v1 = v2 = v1;\r\n// ^ Type 'unknown[]' is not assignable to type 'IsSub\u003c[1, 2, 3, 4], [2, 3, 4]\u003e'.(2322)\r\n\r\nv1 = v2 = v0; // Ok\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nThe generic type being provided with correct parameters `IsSub\u003c[1, 2, 3, 4], [2, 3, 4]\u003e` appears to get evaluated into a conditianal type literal `[1, 2, 3, 4] extends [...infer B, 2, 3, 4, ...any[]] ? B : never`\r\n\r\n### 🙂 Expected behavior\r\n\r\nIf such a generic has an error in syntax or faces some limitation in the use, the compiler should raise an exception. If it is correct (it looks correct) it must be evaluated into a definitive type, e.g. `unknown[]`. In contrast, if we change generic:\r\n\r\n```ts\r\ntype IsSub\u003cM extends any[], S extends any[]\u003e = M extends [\r\n  ...SubGuard\u003cM[number], infer B\u003e,\r\n  ...S\r\n]\r\n  ? B\r\n  : never;\r\n```\r\nit gives us:\r\n\r\n```ts\r\ntype E0 = IsSub\u003c[1, 2, 3, 4], [2, 3, 4]\u003e; //  Evaluated: type E0 = [1]\r\n```\r\nthat is expected.\r\n\r\n---\r\nOne more inconsistency in the example:\r\n\r\nIf we add: \r\n```ts\r\ndeclare let v3: never;\r\n\r\nv3 = v0;\r\n```\r\nthe compiler shows an error:\r\n```\r\nType 'IsSub\u003c[1, 2, 3, 4], [2, 3, 4]\u003e' is not assignable to type 'never'.\r\n  Type '[M[number]]' is not assignable to type 'never'.(2322)\r\n```\r\nwhere we can see type `[M[number]]` which is absurd since `M` is not in the context and is the name of a variable in the original generic `type IsSub\u003cM extends any[], S extends any[]\u003e`.\r\n\r\nIf we substitute `M` with `[1, 2, 3, 4]` it still does not answer what actual type we have:\r\n```ts\r\ndeclare let v4: [[1, 2, 3, 4][number]];\r\n\r\nv0 = v4; // Error\r\nv4 = v0; // Ok\r\n```\r\n\r\n[Playground](https://www.typescriptlang.org/play?ts=4.1.3#code/C4TwDgpgBAygrgIwOJwIYCcAmAeAggGigA0oIAPYCAO0wGcoBtXAXQD4oBeYgbgChfQkKAEla8BNgCypCtTpRUVEA2aEYMyjXqLlbTlGnlN8hryhQAdFfEoMOSQypwAtggjpVUAJZUAZu6gAIVZ8M0trUPMrCx0VXmYwgH4gsIAuKCoIADd3PgFwaABRAAZ9UXFsBgBGQgAmQgBmQgAWTwZ6qCaoVtZuKAB6fvNCrNQAGzRKTHTBItKuarrGluYNOXoGaJ9-dCClzpbCaNjmVeTAqHTMnPR+WahCqv1FqA6u1rWtRi2-AMD995HKwnM5BS4ZbK5AZDe6PfRwKgAayoAHsAO5UOK8TAQADGYww0DGEGAUCyxXSJT4OPxhKgxNJWSqlKq1LxBPQRJJZNq6QRyPRmOYeXM5P0TPFtXFrN4gygAD0oAAVApQADk-NRGJUau89FRpNQtFoXgA5lRUAhiVBgCibaq1eVEJUaq9lt02m8Vqw1RYABS1Bq1WoASn4Eq4WSlkeKfTlAHlEfwaRyuYyGldIegRWSGuLY7KhoqVUJHWJnS8vR7CO13T1dV59SjDcazRardBbfbS9d3L7C+ZByXoGqGA4nK53KcG02WybzZbrV37mre+hfQGg6Hk+y6Qyyc10gxK3XmI4XG4PMLw-MD3GhoV0OgUbcss18-eoIneEA)","author":{"url":"https://github.com/turtleflyer","@type":"Person","name":"turtleflyer"},"datePublished":"2021-02-04T04:41:50.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/42636/TypeScript/issues/42636"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:c2a6b107-c1b7-5807-ea22-24851db166df
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idDDF8:70D59:191862:21F50F:6A626CB9
html-safe-noncee609544f347c83dfdb5ad15b15828ed6699e44d850c980447abf13334d0c3d3a
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEREY4OjcwRDU5OjE5MTg2MjoyMUY1MEY6NkE2MjZDQjkiLCJ2aXNpdG9yX2lkIjoiMTA1NzUyMjk4MTMwMzExOTAzMyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmace61dd7e6c481e48b193e2bf2f49fa5800ab028fe8370d90f2ef99d80e5cd5493
hovercard-subject-tagissue:800924916
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/42636/issue_layout
twitter:imagehttps://opengraph.githubassets.com/d86f41c2318af861446cc832238818ba0e87ae466bb96a772e792592e1470062/microsoft/TypeScript/issues/42636
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/d86f41c2318af861446cc832238818ba0e87ae466bb96a772e792592e1470062/microsoft/TypeScript/issues/42636
og:image:altBug Report 🔎 Search Terms generic conditional type inference not evaluated 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ for entries about...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameturtleflyer
hostnamegithub.com
expected-hostnamegithub.com
None19769ef9d383a84eeab48bb9b309078c20f4532b73eae2f9713b18406513e0ad
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
release76dc6b11f13eaeec1329217c9f16c262ade27a1e
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/42636#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F42636
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
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
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://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
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F42636
Sign up https://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/42636
Reloadhttps://github.com/microsoft/TypeScript/issues/42636
Reloadhttps://github.com/microsoft/TypeScript/issues/42636
Please reload this pagehttps://github.com/microsoft/TypeScript/issues/42636
microsoft https://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Notifications https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Fork 13.6k https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Star 110k https://github.com/login?return_to=%2Fmicrosoft%2FTypeScript
Code https://github.com/microsoft/TypeScript
Issues 5k+ https://github.com/microsoft/TypeScript/issues
Pull requests 21 https://github.com/microsoft/TypeScript/pulls
Actions https://github.com/microsoft/TypeScript/actions
Projects https://github.com/microsoft/TypeScript/projects
Wiki https://github.com/microsoft/TypeScript/wiki
Security and quality 0 https://github.com/microsoft/TypeScript/security
Insights https://github.com/microsoft/TypeScript/pulse
Code https://github.com/microsoft/TypeScript
Issues https://github.com/microsoft/TypeScript/issues
Pull requests https://github.com/microsoft/TypeScript/pulls
Actions https://github.com/microsoft/TypeScript/actions
Projects https://github.com/microsoft/TypeScript/projects
Wiki https://github.com/microsoft/TypeScript/wiki
Security and quality https://github.com/microsoft/TypeScript/security
Insights https://github.com/microsoft/TypeScript/pulse
#42747https://github.com/microsoft/TypeScript/pull/42747
Generic with type inference in conditional type not evaluated into definitive typehttps://github.com/microsoft/TypeScript/issues/42636#top
#42747https://github.com/microsoft/TypeScript/pull/42747
https://github.com/ahejlsberg
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
TypeScript 4.3.0https://github.com/microsoft/TypeScript/milestone/134
https://github.com/turtleflyer
turtleflyerhttps://github.com/turtleflyer
on Feb 4, 2021https://github.com/microsoft/TypeScript/issues/42636#issue-800924916
Playground link with relevant codehttps://www.typescriptlang.org/play?ts=4.1.3#code/C4TwDgpgBAygrgIwOJwIYCcAmAeAggGigA0oIAPYCAO0wGcoBtXAXQD4oBeYgbgChfQkKAEla8BNgCypCtTpRUVEA2a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L7C+ZByXoGqGA4nK53KcG02WybzZbrV37mre+hfQGg6Hk+y6Qyyc10gxK3XmI4XG4PMLw-MD3GhoV0OgUbcss18-eoIneEA
ahejlsberghttps://github.com/ahejlsberg
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Fix AvailableA PR has been opened for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fix%20Available%22
TypeScript 4.3.0https://github.com/microsoft/TypeScript/milestone/134
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.