René's URL Explorer Experiment


Title: Transformers in a map generated via a Mapped Type with Key Remapping are erroneously inferred to return `any` · Issue #57097 · microsoft/TypeScript · GitHub

Open Graph Title: Transformers in a map generated via a Mapped Type with Key Remapping are erroneously inferred to return `any` · Issue #57097 · microsoft/TypeScript

X Title: Transformers in a map generated via a Mapped Type with Key Remapping are erroneously inferred to return `any` · Issue #57097 · microsoft/TypeScript

Description: 🔎 Search Terms "mapped types", "key remapping", "indexed access type" 🕗 Version & Regression Information This is the behavior in every version I tried (5.2.2, 5.3.2, 5.4.0-dev.20240119), and I reviewed the FAQ. ⏯ Playground Link https://...

Open Graph Description: 🔎 Search Terms "mapped types", "key remapping", "indexed access type" 🕗 Version & Regression Information This is the behavior in every version I tried (5.2.2, 5.3.2, 5.4.0-dev.20240119), and I revi...

X Description: 🔎 Search Terms "mapped types", "key remapping", "indexed access type" 🕗 Version & Regression Information This is the behavior in every version I tried (5.2.2, 5.3....

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Transformers in a map generated via a Mapped Type with Key Remapping are erroneously inferred to return `any`","articleBody":"### 🔎 Search Terms\n\n\"mapped types\", \"key remapping\", \"indexed access type\"\n\n### 🕗 Version & Regression Information\n\n- This is the behavior in every version I tried (5.2.2, 5.3.2, 5.4.0-dev.20240119), and I reviewed the FAQ.\n\n### ⏯ Playground Link\n\nhttps://www.typescriptlang.org/play?target=99&ts=5.4.0-dev.20240119#code/KYDwDg9gTgLgBDAnmYcByEAmwCSA7GYKAMwEMBjYAHgBkBLQqUgGwBVlVRC9MBnOXjCh08AczgBeAUJGiAfJLgBvAFBx1CDgC449Ri3YoA3CoC+JlaEixNKOAGUidFnQBewTPZliAssBikigBKwOTQmFSCwmIANNLR4gA+cACuPMDEIh5yFlbQ8Eh2ACIQALYAoiBCFISYGNhFpAGKqhpweFjAhsA6UbImbaX+pDqOwi7unt6ifgEm5iqW4Pm2qPVdECWlY87MbkRU63BcwDz86-iMZJQKUgAUahod2DrrMSoAlJIKOxMeXglZqRcssbIU1p0gb89u4oD5SGBDp0AKp4OgQPDHKqnPjoTqXIjXYC3ZSPdQAbSOIjx2FR6MxpHOnXJAHJwSyALoc16dVibMrQ-ZQJHYHJmCxhPCCOAAC0ZiiorCx3FxEAARgArUIwOQPNoQHSsd5tADWvWmcGSeBSpTVREtAkQtogzHeHx0JrgdH4JuAiAgxDgSokCgA8prtQA6OW8UMAdzwdwgcRNHwlGOlQkQgvcyN4snhYDAsgVSpOZxpuAIhIoxL1GlKCOLYh52ChTj+cIRirkxqenUNbu+pLadEDdxjd0bRdkcWewEj4I+X1abQ0kulgSk0+bonJ88XHA5FjX64z8DVilId3nacWp-UUH8KSgDJvnTvbVM940MBlUAgON2mAIDunKKAAKgO4WVRXgUiLfIPHaTpVhZO9zCAA\n\n### 💻 Code\n\n```ts\r\nexport type NodeInterface\u003cLiteralType extends string = string> = {\r\n    type: LiteralType;\r\n};\r\n\r\nexport type SerializedStringMeta = Record\u003cstring, string | undefined>;\r\n\r\nexport type DomExtractedNodeData = {\r\n    nodeType: string;\r\n    meta: SerializedStringMeta;\r\n};\r\n\r\nexport type NodeToDomSerializer\u003cNode extends NodeInterface> = (\r\n    node: Node,\r\n) => SerializedStringMeta;\r\n\r\nexport type NodeMetaSerializerMap\u003cNodeUnion extends NodeInterface> = {\r\n    [Node in NodeUnion as Node['type']]: NodeToDomSerializer\u003cNode>;\r\n};\r\n\r\nconst has = \u003cT extends object>(\r\n    o: T,\r\n    k: string | number | symbol,\r\n): k is keyof T => Object.hasOwn(o, k);\r\n\r\nconst trySerializeUsingMapping = \u003cT extends NodeInterface>(\r\n    mapping: NodeMetaSerializerMap\u003cT>,\r\n    node: T,\r\n) => {\r\n    if (has(mapping, node.type)) {\r\n        const a = mapping[node.type];\r\n\r\n        const b = a(node);\r\n\r\n        return a(node);\r\n    }\r\n\r\n    throw new TypeError('Unsupported node type');\r\n};\r\n```\r\n\n\n### 🙁 Actual behavior\n\nType of the variable `a` is correctly inferred to be `NodeMetaSerializerMap\u003cT>[keyof NodeMetaSerializerMap\u003cT>]`. To be rigorous this should be `NodeToDomSerializer\u003cT>`.\r\n\r\nType of variable `b`, however, is inferred to be `any`. Compiler doesn't warn me about this, and as you can understand, this could lead to all sorts of potential `any`-leakages. Compiler option `strict` doesn't change this as well.\n\n### 🙂 Expected behavior\n\nI expect type of the variable `b` to be correctly inferred as `SerializedStringMeta`, or at least some kind of error to be shown in the call site of `a(node)`.\n\n### Additional information about the issue\n\nI've also reviewed [this](https://github.com/microsoft/TypeScript/pull/47109) pull request. I've tried the following work-around:\r\n\r\n```typescript\r\ntype TypeToNodeMapping\u003cNode extends NodeInterface> = {\r\n    [K in Node as Node['type']]: Node;\r\n};\r\n\r\nexport type NodeMetaSerializerMap\u003cNodeUnion extends NodeInterface> = {\r\n    [K in keyof TypeToNodeMapping\u003cNodeUnion>]: NodeToDomSerializer\u003c\r\n        TypeToNodeMapping\u003cNodeUnion>[K]\r\n    >;\r\n};\r\n```\r\nThis results in a following error being shown at the call site for `a(node)`:\r\n\r\n\u003cimg width=\"604\" alt=\"image\" src=\"https://github.com/microsoft/TypeScript/assets/1677844/07e2c227-0ebd-4d67-9f51-c7316d49d6e0\">\r\n\r\nThis also seems like a weird behaviour, because I've tested different things and verified that `TypeToNodeMapping\u003cNodeInterface>[NodeInterface['type']]` is correctly resolved as `NodeInterface`. Seems to me like the compiler is for some reason refusing to unpack the types further, despite the fact it seems safe to use the upper boundary `NodeInterface` when resolving types for `T`.\r\n","author":{"url":"https://github.com/brotheroftux","@type":"Person","name":"brotheroftux"},"datePublished":"2024-01-19T16:18:51Z","url":"https://github.com/microsoft/TypeScript/issues/57097"}

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:c83b1ca8-a553-7124-c173-6e237f556d68
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id86D2:3E1BDD:239A4:2FC51:6B017BC4
html-safe-nonce80b0f21a707125c03b476745424ba6bcf4a1ea3b0a496ad16d86e2bdf68fba01
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4NkQyOjNFMUJERDoyMzlBNDoyRkM1MTo2QjAxN0JDNCIsInZpc2l0b3JfaWQiOiI2MDE2MzE5NTMzNTI1MDcyODM2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac046032a3712b0e3e288e0d568c9fec5ba0b773d68a871f0fc832711196cd8c90
hovercard-subject-tagissue:2090868120
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/57097/issue_layout
twitter:imagehttps://opengraph.githubassets.com/b64ddbf7abb84707c10dd89280d4688eddefeade8fb0b85dea4fa32efb4346ed/microsoft/TypeScript/issues/57097
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/b64ddbf7abb84707c10dd89280d4688eddefeade8fb0b85dea4fa32efb4346ed/microsoft/TypeScript/issues/57097
og:image:alt🔎 Search Terms "mapped types", "key remapping", "indexed access type" 🕗 Version & Regression Information This is the behavior in every version I tried (5.2.2, 5.3.2, 5.4.0-dev.20240119), and I revi...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebrotheroftux
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/57097#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F57097
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%2F57097
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/57097
Reloadhttps://github.com/microsoft/TypeScript/issues/57097
Reloadhttps://github.com/microsoft/TypeScript/issues/57097
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/57097
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/57097
Transformers in a map generated via a Mapped Type with Key Remapping are erroneously inferred to return anyhttps://github.com/microsoft/TypeScript/issues/57097#top
https://github.com/ahejlsberg
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%22
https://github.com/brotheroftux
Daniel Kuznetsov (brotheroftux)https://github.com/brotheroftux
on Jan 19, 2024https://github.com/microsoft/TypeScript/issues/57097#issue-2090868120
https://www.typescriptlang.org/play?target=99&ts=5.4.0-dev.20240119#code/KYDwDg9gTgLgBDAnmYcByEAmwCSA7GYKAMwEMBjYAHgBkBLQqUgGwBVlVRC9MBnOXjCh08AczgBeAUJGiAfJLgBvAFBx1CDgC449Ri3YoA3CoC+JlaEixNKOAGUidFnQBewTPZliAssBikigBKwOTQmFSCwmIANNLR4gA+cACuPMDEIh5yFlbQ8Eh2ACIQALYAoiBCFISYGNhFpAGKqhpweFjAhsA6UbImbaX+pDqOwi7unt6ifgEm5iqW4Pm2qPVdECWlY87MbkRU63BcwDz86-iMZJQKUgAUahod2DrrMSoAlJIKOxMeXglZqRcssbIU1p0gb89u4oD5SGBDp0AKp4OgQPDHKqnPjoTqXIjXYC3ZSPdQAbSOIjx2FR6MxpHOnXJAHJwSyALoc16dVibMrQ-ZQJHYHJmCxhPCCOAAC0ZiiorCx3FxEAARgArUIwOQPNoQHSsd5tADWvWmcGSeBSpTVREtAkQtogzHeHx0JrgdH4JuAiAgxDgSokCgA8prtQA6OW8UMAdzwdwgcRNHwlGOlQkQgvcyN4snhYDAsgVSpOZxpuAIhIoxL1GlKCOLYh52ChTj+cIRirkxqenUNbu+pLadEDdxjd0bRdkcWewEj4I+X1abQ0kulgSk0+bonJ88XHA5FjX64z8DVilId3nacWp-UUH8KSgDJvnTvbVM940MBlUAgON2mAIDunKKAAKgO4WVRXgUiLfIPHaTpVhZO9zCAAhttps://www.typescriptlang.org/play?target=99&ts=5.4.0-dev.20240119#code/KYDwDg9gTgLgBDAnmYcByEAmwCSA7GYKAMwEMBjYAHgBkBLQqUgGwBVlVRC9MBnOXjCh08AczgBeAUJGiAfJLgBvAFBx1CDgC449Ri3YoA3CoC+JlaEixNKOAGUidFnQBewTPZliAssBikigBKwOTQmFSCwmIANNLR4gA+cACuPMDEIh5yFlbQ8Eh2ACIQALYAoiBCFISYGNhFpAGKqhpweFjAhsA6UbImbaX+pDqOwi7unt6ifgEm5iqW4Pm2qPVdECWlY87MbkRU63BcwDz86-iMZJQKUgAUahod2DrrMSoAlJIKOxMeXglZqRcssbIU1p0gb89u4oD5SGBDp0AKp4OgQPDHKqnPjoTqXIjXYC3ZSPdQAbSOIjx2FR6MxpHOnXJAHJwSyALoc16dVibMrQ-ZQJHYHJmCxhPCCOAAC0ZiiorCx3FxEAARgArUIwOQPNoQHSsd5tADWvWmcGSeBSpTVREtAkQtogzHeHx0JrgdH4JuAiAgxDgSokCgA8prtQA6OW8UMAdzwdwgcRNHwlGOlQkQgvcyN4snhYDAsgVSpOZxpuAIhIoxL1GlKCOLYh52ChTj+cIRirkxqenUNbu+pLadEDdxjd0bRdkcWewEj4I+X1abQ0kulgSk0+bonJ88XHA5FjX64z8DVilId3nacWp-UUH8KSgDJvnTvbVM940MBlUAgON2mAIDunKKAAKgO4WVRXgUiLfIPHaTpVhZO9zCAA
thishttps://github.com/microsoft/TypeScript/pull/47109
https://private-user-images.githubusercontent.com/1677844/298130463-07e2c227-0ebd-4d67-9f51-c7316d49d6e0.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3OTUyNTk2MzIsIm5iZiI6MTc5NTI1OTMzMiwicGF0aCI6Ii8xNjc3ODQ0LzI5ODEzMDQ2My0wN2UyYzIyNy0wZWJkLTRkNjctOWY1MS1jNzMxNmQ0OWQ2ZTAucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI2MTEyMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNjExMjFUMTEwODUyWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NGRiOTYwZjNjNzdlYjY4YjM2NmQ3OThiMGI1ZmFhYThiNWUzYWVlMjU5M2VhYjNlM2MzZGJiNWMxNjI1ODk3YSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmcmVzcG9uc2UtY29udGVudC10eXBlPWltYWdlJTJGcG5nIn0.6G1bZ8zjIW2hnrnbasRwk7RWXVF2rmU-qKjxogXfL00
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Needs InvestigationThis issue needs a team member to investigate its status.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Investigation%22
on Jan 19, 2024https://github.com/microsoft/TypeScript/issues/57097#event-11539904310
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jan 19, 2024https://github.com/microsoft/TypeScript/issues/57097#event-11539904924
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jan 30, 2024https://github.com/microsoft/TypeScript/issues/57097#issuecomment-1917686211
#53066https://github.com/microsoft/TypeScript/pull/53066
#57202https://github.com/microsoft/TypeScript/pull/57202
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jan 30, 2024https://github.com/microsoft/TypeScript/issues/57097#issuecomment-1917752790
#55129https://github.com/microsoft/TypeScript/issues/55129
https://github.com/ahejlsberg
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
on Jan 30, 2024https://github.com/microsoft/TypeScript/issues/57097#issuecomment-1917755345
#57202https://github.com/microsoft/TypeScript/pull/57202
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%22
Needs InvestigationThis issue needs a team member to investigate its status.https://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Needs%20Investigation%22
on Jan 30, 2024https://github.com/microsoft/TypeScript/issues/57097#event-11646587348
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jan 30, 2024https://github.com/microsoft/TypeScript/issues/57097#event-11646588469
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/57097
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/57097
Anders Hejlsberg (ahejlsberg)https://github.com/ahejlsberg
FixedA PR has been merged for this issuehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Fixed%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.