René's URL Explorer Experiment


Title: Incorrect optimization for keyof Mapped type · Issue #43920 · microsoft/TypeScript · GitHub

Open Graph Title: Incorrect optimization for keyof Mapped type · Issue #43920 · microsoft/TypeScript

X Title: Incorrect optimization for keyof Mapped type · Issue #43920 · microsoft/TypeScript

Description: I have this Mapped type which creates a type with just those fields of T that are extended by B. It seems to work. type FieldsExtendedBy = {[K in keyof T as (B extends T[K] ? K :never)] : T[K]}; But this one, to extract the keys of ...

Open Graph Description: I have this Mapped type which creates a type with just those fields of T that are extended by B. It seems to work. type FieldsExtendedBy = {[K in keyof T as (B extends T[K] ? K :never)] : T[K]...

X Description: I have this Mapped type which creates a type with just those fields of T that are extended by B. It seems to work. type FieldsExtendedBy<T,B> = {[K in keyof T as (B extends T[K] ? K :never)] ...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect optimization for keyof Mapped type","articleBody":"I have this Mapped type which creates a type with just those fields of T that are extended by B. It seems to work.\r\n\r\n```type FieldsExtendedBy\u003cT,B> = {[K in keyof T as (B extends T[K] ? K :never)] : T[K]};```\r\n\r\nBut this one, to extract the keys of those fields, doesn't:\r\n\r\n```type KeysExtendedByFails\u003cT,B> = keyof {[K in keyof T as (B extends T[K] ? K :never)] : T[K]};```\r\n\r\nKeysExtendedByFails always includes all or none of the keys of the original T. I've setup a playground [here](https://www.typescriptlang.org/play?ts=4.2.3#code/LAKALgngDgpgBAMQJYwDYBMDOBRAHmGAO3RnQCEIAeAFQBoyA+OAXjgG8BtAaTiULgDWMCAHsAZnGpwAhpjgAKMnBj4iWSdwC6cAPxweALkIwAbjABOASm0GNXTQF8A3KFCRY+4TlXFSFAOoi5gKYNPRMrEKiEpw8fILC4pIycvLUWso+6gCuhAKEIgDu-HqKmQTEcun2uvpwRqYWlrbGZlY2do4u4NDwXF54FSTkEAjSSKihdIwsCdHs3Lz8UUlSsgpKKkNVGXqGrU0d1V2uIHwE5mLSAMbwAILscLj1cITZALYARhZOcA6g5wsV1ucCUbDgEBemDA5j4AHNfv8zoQLsD4ABhcpqORguAALx0tk+IhEqBg0kIiNOgMuN3gAFlHtJbHdfp8XmRftcXpikaAxLlrmAkCJ+HCSeh5NlbP0IN4hn4IIFgqF6bRQQxLFCYfD2KA4HBzDAwNlzPxst0kQLCEKRfxPtJJdLPHLBmpFWMJqr1YwtbZobDCHC9SADUaTWa4BbQHyQAB6ONwMAACyQclF8CuXrgorg70hfGh0lQqGkwtzSQALAA6ABM1YAzOrPtkwHBCkEQksk8n4FBSxA4eYRLl0PzBeX+B2VQB9Pgz-vSQfD0dS2wrCTINBYN2+EaUNW+7WB4NsfWG42m82W07W2256chGcUiCFJdrxAoDDy937w+al5cnyIp+DPUMLwja8Y1vCc7TgB1zHkLVwXPcMrzgDhzwNcURElAAiaQ8MsdUEzgLNJhSTJYCFUhq1BOB0BEGA5AKNstjUOA7iwuAcPwz4iNobjePkPDrgE7iHXwwjiLgUjchUaiCHQVBIUfTA6KURjmNeEQ2KyTiJMdET+OIwz8LE0zwINNS50IBcByHEdiBE6SSMTa4giNIUVLI8YKPiRdlyc9Bm1bHS2zEII83gQokBTOAa3rBtuJs+dAsc1c8JMwSrPbTtMFs+ylwy5zRPE8DNBvEBxxtSd4OkPEkJDMNL0jTDcpsl83wgeQ2GZNhcAMStawcWhPgMNgIAMLKGrw0brgmvEDBhbIYFoKaZvMOaHBk0jyLkdYFJgGj0A0himJY3SsWIAyOvy59CFfd8+omwbhocHa3N87NDtwRTaLgek00wXV2QpdA4GudVwbgVA4osYs4EwZMRwwcK4GTaQzBkFL7q657xsm6aHTxObaAWtglpWtaNoQ7bdsTNTz00GMgA), and hovering over the use of KeysExtendedByFails in the function bad in the playground example shows the definition has been incorrectly transformed to:\r\n\r\n```type KeysExtendedByFails\u003cT, B> = B extends T[keyof T] ? keyof T : never```\r\n\r\nwhich is obviously wrong.\r\n\r\nI have another definition, \r\n\r\n```type KeysExtendedByWorks\u003cT,B> = keyof {[K in keyof T as (T[K] extends unknown ? (B extends T[K] ? K :never): never)] : T[K]};```\r\n\r\nwhich works - although `T[K] extends unknown` is pretty much a no op.\r\n\r\nAlso applying keyof to FieldsExtendedBy seems to work in the playground (versions 4.1.5 and later), but fails for me with 4.2.3. I assume there's a setting which is affecting whether it works or not.\r\n\r\n\r\n\r\n","author":{"url":"https://github.com/markw65","@type":"Person","name":"markw65"},"datePublished":"2021-05-01T17:13:41Z","url":"https://github.com/microsoft/TypeScript/issues/43920"}

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:ba09b648-b00d-3280-6b1d-81b9b36b9c5c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idEB68:4BB79:4B8B46C:6035E5D:6B026B49
html-safe-nonce14c5fa44a18a42b30b608804928d6312051a2b3306976116d05eddc1d9f34c1c
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFQjY4OjRCQjc5OjRCOEI0NkM6NjAzNUU1RDo2QjAyNkI0OSIsInZpc2l0b3JfaWQiOiI4NzQwMTExNDAyMzYwMDA3NDk3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac775f8b1b2d51ce299f08111379d99b68f415c17015ef70f01ed8c76161c37427
hovercard-subject-tagissue:873724974
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/43920/issue_layout
twitter:imagehttps://opengraph.githubassets.com/c96842ebdb2136baa4963ecf8f19636916464ecff69ae3c9b038f86e78171d0a/microsoft/TypeScript/issues/43920
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/c96842ebdb2136baa4963ecf8f19636916464ecff69ae3c9b038f86e78171d0a/microsoft/TypeScript/issues/43920
og:image:altI have this Mapped type which creates a type with just those fields of T that are extended by B. It seems to work. type FieldsExtendedBy = {[K in keyof T as (B extends T[K] ? K :never)] : T[K]...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamemarkw65
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
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
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/43920#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F43920
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%2F43920
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/43920
Reloadhttps://github.com/microsoft/TypeScript/issues/43920
Reloadhttps://github.com/microsoft/TypeScript/issues/43920
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests313 (313)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/43920
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/43920
Incorrect optimization for keyof Mapped typehttps://github.com/microsoft/TypeScript/issues/43920#top
Needs More InfoThe issue still hasn't been fully clarifiedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20More%20Info%22
https://github.com/markw65
markw65https://github.com/markw65
on May 1, 2021https://github.com/microsoft/TypeScript/issues/43920#issue-873724974
herehttps://www.typescriptlang.org/play?ts=4.2.3#code/LAKALgngDgpgBAMQJYwDYBMDOBRAHmGAO3RnQCEIAeAFQBoyA+OAXjgG8BtAaTiULgDWMCAHsAZnGpwAhpjgAKMnBj4iWSdwC6cAPxweALkIwAbjABOASm0GNXTQF8A3KFCRY+4TlXFSFAOoi5gKYNPRMrEKiEpw8fILC4pIycvLUWso+6gCuhAKEIgDu-HqKmQTEcun2uvpwRqYWlrbGZlY2do4u4NDwXF54FSTkEAjSSKihdIwsCdHs3Lz8UUlSsgpKKkNVGXqGrU0d1V2uIHwE5mLSAMbwAILscLj1cITZALYARhZOcA6g5wsV1ucCUbDgEBemDA5j4AHNfv8zoQLsD4ABhcpqORguAALx0tk+IhEqBg0kIiNOgMuN3gAFlHtJbHdfp8XmRftcXpikaAxLlrmAkCJ+HCSeh5NlbP0IN4hn4IIFgqF6bRQQxLFCYfD2KA4HBzDAwNlzPxst0kQLCEKRfxPtJJdLPHLBmpFWMJqr1YwtbZobDCHC9SADUaTWa4BbQHyQAB6ONwMAACyQclF8CuXrgorg70hfGh0lQqGkwtzSQALAA6ABM1YAzOrPtkwHBCkEQksk8n4FBSxA4eYRLl0PzBeX+B2VQB9Pgz-vSQfD0dS2wrCTINBYN2+EaUNW+7WB4NsfWG42m82W07W2256chGcUiCFJdrxAoDDy937w+al5cnyIp+DPUMLwja8Y1vCc7TgB1zHkLVwXPcMrzgDhzwNcURElAAiaQ8MsdUEzgLNJhSTJYCFUhq1BOB0BEGA5AKNstjUOA7iwuAcPwz4iNobjePkPDrgE7iHXwwjiLgUjchUaiCHQVBIUfTA6KURjmNeEQ2KyTiJMdET+OIwz8LE0zwINNS50IBcByHEdiBE6SSMTa4giNIUVLI8YKPiRdlyc9Bm1bHS2zEII83gQokBTOAa3rBtuJs+dAsc1c8JMwSrPbTtMFs+ylwy5zRPE8DNBvEBxxtSd4OkPEkJDMNL0jTDcpsl83wgeQ2GZNhcAMStawcWhPgMNgIAMLKGrw0brgmvEDBhbIYFoKaZvMOaHBk0jyLkdYFJgGj0A0himJY3SsWIAyOvy59CFfd8+omwbhocHa3N87NDtwRTaLgek00wXV2QpdA4GudVwbgVA4osYs4EwZMRwwcK4GTaQzBkFL7q657xsm6aHTxObaAWtglpWtaNoQ7bdsTNTz00GMgA
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
UnactionableThere isn't something we can do with this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Unactionable%22
Needs More InfoThe issue still hasn't been fully clarifiedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20More%20Info%22
UnactionableThere isn't something we can do with this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Unactionable%22
on May 3, 2021https://github.com/microsoft/TypeScript/issues/43920#event-4679889445
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on May 3, 2021https://github.com/microsoft/TypeScript/issues/43920#issuecomment-831491986
https://github.com/markw65
markw65https://github.com/markw65
on May 4, 2021https://github.com/microsoft/TypeScript/issues/43920#issuecomment-831640101
comment belowhttps://github.com/microsoft/TypeScript/issues/43920#issuecomment-832224134
https://github.com/markw65
markw65https://github.com/markw65
on May 4, 2021https://github.com/microsoft/TypeScript/issues/43920#issuecomment-832164749
https://github.com/markw65
markw65https://github.com/markw65
on May 4, 2021https://github.com/microsoft/TypeScript/issues/43920#issuecomment-832218158
https://github.com/markw65
markw65https://github.com/markw65
on May 4, 2021https://github.com/microsoft/TypeScript/issues/43920#issuecomment-832224134
here'shttps://www.typescriptlang.org/play?ts=4.2.3#code/C4TwDgpgBAYglhANgEwM4FEAewIDtkTIBCIAPACoA0URAfFALxQDeAsAFBRQDaA0lHFxQA1hBAB7AGZRyUAIaoaUCNjxoZfALpQA-FH4AuKLggA3CACdNR8loDcHAL4P2HQTguS5AY2gBBFg4uTCNcAFcAWwAjSxdHN1wPL18lNk4oECNUYAtBAHM4hKSfaABhZVV8RSJA9IAvHSMo8XFECDlcQtd2d0tk6ABZWq45Iz8XLiijIgmobyNSro5vRAVFGBaKajphqCi5ZAAKMJCRMSlYBBQMSoJiMioaWgBKXa4LCGAwiyET2fj2ACOJIwrhvMA4OIhPsLIdXmkuN4odkoJIWoxjBAAO6wTYDSh0OGzD5fH48IJcVEtAB0+yOACI5PTntQAPSsqCglSQcGERAgKBY8QWYSoalKZDiCCKXDiYAVHD4KB+ClcNHiWkHQ70qLMyiqqkauna7x6imaLpAA
https://github.com/markw65
markw65https://github.com/markw65
on May 4, 2021https://github.com/microsoft/TypeScript/issues/43920#issuecomment-832289881
Here's my stab at a fixhttps://github.com/microsoft/TypeScript/commit/7c775d33ffbc7ac14402fe7a21cae9fb3bf2dbaa
https://github.com/markw65
markw65https://github.com/markw65
on May 9, 2021https://github.com/microsoft/TypeScript/issues/43920#issuecomment-835929870
#44019https://github.com/microsoft/TypeScript/issues/44019
#44019https://github.com/microsoft/TypeScript/issues/44019
markw65https://github.com/markw65
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on May 9, 2021https://github.com/microsoft/TypeScript/issues/43920#event-4712165472
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/43920
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/43920
Needs More InfoThe issue still hasn't been fully clarifiedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20More%20Info%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.