Title: Design Meeting Notes, 3/8/2022 · Issue #53169 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 3/8/2022 · Issue #53169 · microsoft/TypeScript
X Title: Design Meeting Notes, 3/8/2022 · Issue #53169 · microsoft/TypeScript
Description: Using a Homomorphic Mapped Type For Omit #53134 interface Obj { readonly a: string; b?: number; c: boolean; } // "homomorphic" - preserves all modifiers in BoxedObj type Boxify
Open Graph Description: Using a Homomorphic Mapped Type For Omit #53134 interface Obj { readonly a: string; b?: number; c: boolean; } // "homomorphic" - preserves all modifiers in BoxedObj type Boxify
X Description: Using a Homomorphic Mapped Type For Omit #53134 interface Obj { readonly a: string; b?: number; c: boolean; } // "homomorphic" - preserves all modifiers in BoxedObj type Boxify<T> =...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/53169
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 3/8/2022","articleBody":"# Using a Homomorphic Mapped Type For Omit\r\n\r\nhttps://github.com/microsoft/TypeScript/pull/53134\r\n\r\n```ts\r\ninterface Obj {\r\n readonly a: string;\r\n b?: number;\r\n c: boolean;\r\n}\r\n\r\n// \"homomorphic\" - preserves all modifiers in BoxedObj\r\ntype Boxify\u003cT> = {\r\n [K in keyof T]: { value: T[K] }\r\n}\r\ntype BoxedObj = Boxify\u003cObj>;\r\n\r\n\r\n// non-\"homomorphic\" - loses information for BoxedObj2\r\ntype Boxify2\u003cKeys extends keyof Obj> = {\r\n [K in Keys]: { value: Obj[K] }\r\n}\r\ntype BoxedObj2 = Boxify2\u003ckeyof Obj>;\r\n```\r\n\r\n* Today, `Omit` is non-homomorphic. Will not preserve shape.\r\n * Why?\r\n * `keyof` on its own does not retain its source type.\r\n* Today, we can write `Omit` with an `as` clause with `Exclude` - still considered \"homomorphic\" (even though at this point \"homomorphic\" is a misnomer).\r\n\r\n ```ts\r\n type Omit\u003cT, DroppedKeys extends PropertyKey> = {\r\n [K in keyof T as Exclude\u003cK, DroppedKeys>]: T[K]\r\n };\r\n ```\r\n* Switching `Omit` at this point would likely be breaky.\r\n * Existing code where `interface`s extends from `Omit`\r\n* Using a \"homomorphic\" `Omit` makes code flow work better because it can produce union types.\r\n* Could choose to have `Omit` (original) and `MappedOmit` - or `Omit` (improved) and `LegacyOmit`.\r\n * Swapping `Omit` to the \"better\" version is breaky - at least one package breaks.\r\n* We ***really*** don't want to have 2 `Omit`s, and want to push on an improved `Omit`.\r\n * Existing code can write `Pick\u003cT, Omit\u003ckeyof T, DroppedKeys>>`\r\n* Wait, should `Pick` be fixed to use a homomorphic mapped type too?\r\n * OH NOOOOOOOOOOOOOOOOOOOOOOOOOOOO\r\n * Almost had a slam dunk on *just* fixing `Omit`.\r\n* If you fix `Pick`, then `Omit` defined as `Pick\u003cT, Exclude\u003ckeyof T, DroppedKeys>>` is also homomorphic, right?\r\n * *Almost* - but `Omit` is not going to distribute, when we write `Exclude\u003ckeyof T, DroppedKeys>`\r\n* So each of them need to be written as their own mapped types written in terms of `keyof T`.\r\n* Note: the `as` clause for `Pick` should use an intersection, not `Extract`\r\n * Why?\r\n * Intersections are much faster for unions of literals.\r\n * What's the difference in the general case?\r\n * For literal types, they're the same.\r\n * For object types and generic types, intersections combine and don't always \"eradicate\" other types to `never`.\r\n","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2023-03-08T23:26:06Z","url":"https://github.com/microsoft/TypeScript/issues/53169"}
| 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:b6196545-dd13-7ed5-d200-92486c2c4707 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B2D8:1FE434:1A75C9:234AF3:6B0187F7 |
| html-safe-nonce | 35ebcd11dc1114775fac11b1d7f7bf9859396e9504c12a1551034c162396fdf5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMkQ4OjFGRTQzNDoxQTc1Qzk6MjM0QUYzOjZCMDE4N0Y3IiwidmlzaXRvcl9pZCI6IjEzMjQyNDM0OTk4MjE5MjYzOTEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1198072aa084a053a7336ddcd62e1bdeed303b208f7be1e18289d2baf2dc96b2 |
| hovercard-subject-tag | issue:1616135139 |
| 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/53169/issue_layout |
| twitter:image | https://opengraph.githubassets.com/34d02515a5824ce5cb82d0796d2c22686f587e9d7ee4f19392fd9e61a3353694/microsoft/TypeScript/issues/53169 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/34d02515a5824ce5cb82d0796d2c22686f587e9d7ee4f19392fd9e61a3353694/microsoft/TypeScript/issues/53169 |
| og:image:alt | Using a Homomorphic Mapped Type For Omit #53134 interface Obj { readonly a: string; b?: number; c: boolean; } // "homomorphic" - preserves all modifiers in BoxedObj type Boxify |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | DanielRosenwasser |
| 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 |
Links:
Viewport: width=device-width