Title: Contextual type can't be provided to a mapped type intersected with an object type · Issue #48812 · microsoft/TypeScript · GitHub
Open Graph Title: Contextual type can't be provided to a mapped type intersected with an object type · Issue #48812 · microsoft/TypeScript
X Title: Contextual type can't be provided to a mapped type intersected with an object type · Issue #48812 · microsoft/TypeScript
Description: Bug Report 🔎 Search Terms intersection, mapped type, contextual type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ ⏯ Playground Link Playground 💻 Code type Action Open Graph Description: Bug Report 🔎 Search Terms intersection, mapped type, contextual type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ ⏯ Playground Link Playg...
X Description: Bug Report 🔎 Search Terms intersection, mapped type, contextual type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ ⏯ Playground Link P...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/48812
X: @github
Domain: github.com
Links:
Viewport: width=device-width
Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Contextual type can't be provided to a mapped type intersected with an object type","articleBody":"# Bug Report\r\n\r\n### 🔎 Search Terms\r\n\r\nintersection, mapped type, contextual type\r\n\r\n### 🕗 Version & Regression Information\r\n\r\n- This is the behavior in every version I tried, and I reviewed the FAQ \r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground](https://www.typescriptlang.org/play?ts=4.6.2#code/C4TwDgpgBAggxsAlgewHYB4AqBRAbhVYKCAD2AIBMBnKAbylEgC4orgAnRVAcygF8AfFAC8UABQRcLHPkIBKEUNzJEFANwAoDV3LsAZgEM40ALJGAFlwgBhNHsTcseAkVLlU1Og3AQWbTjz8QrQaUKxw5hAAtgYsIWFhki5U0s6EmmF8GVBoAPxxoQkA2gDSUFxQMi5FAESMEDUAuo35sAgoGFWExGSUNPT1LGV8ULmVaUQsqEnsAtkjAGR0hWE1AFQ1rfBIaE6ywHOFWRp8WhQQcAA2BuzQegCuqO1oUHC3BuRmEVZ7Lj3ungGPj8HC4vEEYkKcDsDhYX0s01sqHsji6Bw0chYylUmg0bwgHwg8KsYni4UiMQKCWI+xSdBGBn63mYUBqADEAPIcmr8KAAHy8g1ZACEYAAlHl8AA0RxlYTQVISnI5LAkuAUwmCKwSkgAdPU1FAAPRG1jmZD3S4UKAAI2gAHJlfbtdLZSc5JogA)\r\n\r\n### 💻 Code\r\n\r\n\u003c!-- Please post the relevant code sample here as well-->\r\n```ts\r\ntype Action\u003cTEvent extends { type: string }> = (ev: TEvent) => void;\r\n\r\ninterface MachineConfig\u003cTEvent extends { type: string }> {\r\n schema: {\r\n events: TEvent;\r\n };\r\n on?: {\r\n [K in TEvent[\"type\"]]?: Action\u003cTEvent extends { type: K } ? TEvent : never>;\r\n } & {\r\n \"*\"?: Action\u003cTEvent>;\r\n };\r\n}\r\n\r\ndeclare function createMachine\u003cTEvent extends { type: string }>(\r\n config: MachineConfig\u003cTEvent>\r\n): void;\r\n\r\ncreateMachine({\r\n schema: {\r\n events: {} as { type: \"FOO\" } | { type: \"BAR\" },\r\n },\r\n on: {\r\n FOO: (ev) => {\r\n ev.type; // should be 'FOO', but `ev` is typed implicitly as `any`\r\n },\r\n },\r\n});\r\n\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nAn implicit any pop-ups when the contextual type could be, somewhat easily, provided.\r\n\r\n### 🙂 Expected behavior\r\n\r\nThis should just work 😜 I know a workaround for this issue - the workaround is to use a single mapped type instead of an intersection and just \"dispatch\" to the correct value in the template~ part of the mapped type, like [here](https://www.typescriptlang.org/play?ts=4.6.2#code/C4TwDgpgBAggxsAlgewHYB4AqBRAbhVYKCAD2AIBMBnKAbylEgC4orgAnRVAcygF8AfFAC8UABQRcLHPkIBKEUNzJEFANwAoDV3LsAZgEM40ALJGAFlwgBhNHsTcseAkVLlU1Og3AQWbTjz8QrQaUKxw5hAAtgYsIWFhki5U0s6EmmF8GVBoAPxxoQkA2gDSUFxQMi5FAESMEDUAulAAPlA1AFRN+VBlbpQ0nTWFCVC5sAgoGFWEAiMJLPBIaE6yrmQDXvUsZXxjlWlELKhJ7ALZWRp8WhQQcAA2BuzQegCuqJNoUHDPBuRmESsqxcxA2Hho9G2rA4XF4gjEhTgdgcLABlhOtlQ9kcM2AczkLGUqk0Gh+ED+EDRVjE8XCkRiBVGSUIKToewMEO8zHaADEAPJ8mr8VpbHwsGoAIRgACUhXwADSFBWFNCMhL8vksCS4BTCYLzRK4AB09TUUAA9ObykREDQNQBCebKzKKvhyTRAA). However, this is way less ergonomic than an intersection AND the mapped type is no longer homomorphic which could matter for some cases (well, the original mapped type here is not homomorphic either, but it could be)\r\n\r\nI already have a draft PR open to fix this issue, [here](https://github.com/microsoft/TypeScript/pull/48668). I only need some help with the stuff mentioned in the comment [here](https://github.com/microsoft/TypeScript/pull/48668#discussion_r849531475)","author":{"url":"https://github.com/Andarist","@type":"Person","name":"Andarist"},"datePublished":"2022-04-22T16:57:32Z","url":"https://github.com/microsoft/TypeScript/issues/48812"}
react-profiling 0 react-import-map react,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-controller voltron_issues_fragments route-action issue_layout fetch-nonce v2:30278a62-2e5f-4e4b-e223-6632af6cbfcb current-catalog-service-hash 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 request-id B51C:33444D:1C51C99:25A628B:6B0163AB html-safe-nonce e682723ef13355340aa2ec001c95df73e0868fe4d0d11e84ccfde7f22eef981c visitor-payload eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNTFDOjMzNDQ0RDoxQzUxQzk5OjI1QTYyOEI6NkIwMTYzQUIiLCJ2aXNpdG9yX2lkIjoiNjI3NTIwNDQyMTA3MjgwNjgyNyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 visitor-hmac bd3aa4c993f8f544287eef131292490ca28fb9a423c14ef44ad301bda31326cd hovercard-subject-tag issue:1212580860 github-keyboard-shortcuts repository,issues,copilot google-site-verification Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I octolytics-url https://collector.github.com/github/collect analytics-location / fb:app_id 1401488693436528 apple-itunes-app app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/48812/issue_layout twitter:image https://opengraph.githubassets.com/4fbf4e385286b39b35197282e35aa0bb56a72a7405d899b6a929b8f1dabc9d58/microsoft/TypeScript/issues/48812 twitter:card summary_large_image og:image https://opengraph.githubassets.com/4fbf4e385286b39b35197282e35aa0bb56a72a7405d899b6a929b8f1dabc9d58/microsoft/TypeScript/issues/48812 og:image:alt Bug Report 🔎 Search Terms intersection, mapped type, contextual type 🕗 Version & Regression Information This is the behavior in every version I tried, and I reviewed the FAQ ⏯ Playground Link Playg... og:image:width 1200 og:image:height 600 og:site_name GitHub og:type object og:author:username Andarist hostname github.com expected-hostname github.com None cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c turbo-cache-control no-preview go-import github.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git octolytics-dimension-user_id 6154722 octolytics-dimension-user_login microsoft octolytics-dimension-repository_id 20929025 octolytics-dimension-repository_nwo microsoft/TypeScript octolytics-dimension-repository_public true octolytics-dimension-repository_is_fork false octolytics-dimension-repository_network_root_id 20929025 octolytics-dimension-repository_network_root_nwo microsoft/TypeScript turbo-body-classes logged-out env-production page-responsive disable-turbo false browser-stats-url https://api.github.com/_private/browser/stats browser-errors-url https://api.github.com/_private/browser/errors release 8c77c9e8439031ad54c75a250694842892f693e1 ui-target full theme-color #1e2327 color-scheme light dark react-app-name issues
URLs of crawlers that visited me.