Title: Design Meeting Notes, 12/10/2021 · Issue #47151 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 12/10/2021 · Issue #47151 · microsoft/TypeScript
X Title: Design Meeting Notes, 12/10/2021 · Issue #47151 · microsoft/TypeScript
Description: "Correlated Union Types" #30581 type NumberRecord = { kind: "n", v: number, f: (v: number) => void }; type StringRecord = { kind: "s", v: string, f: (v: string) => void }; type BooleanRecord = { kind: "b", v: boolean, f: (v: boolean) => ...
Open Graph Description: "Correlated Union Types" #30581 type NumberRecord = { kind: "n", v: number, f: (v: number) => void }; type StringRecord = { kind: "s", v: string, f: (v: string) => void }; type BooleanRecord = { ki...
X Description: "Correlated Union Types" #30581 type NumberRecord = { kind: "n", v: number, f: (v: number) => void }; type StringRecord = { kind: "s", v: string, f: (v: string) =&g...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/47151
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 12/10/2021","articleBody":"\r\n# \"Correlated Union Types\"\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/30581\r\n\r\n```ts\r\ntype NumberRecord = { kind: \"n\", v: number, f: (v: number) => void };\r\ntype StringRecord = { kind: \"s\", v: string, f: (v: string) => void };\r\ntype BooleanRecord = { kind: \"b\", v: boolean, f: (v: boolean) => void };\r\ntype UnionRecord = NumberRecord | StringRecord | BooleanRecord;\r\n\r\nfunction processRecord(record: UnionRecord) {\r\n record.f(record.v); // error!\r\n // error msg in TS3.2 and below: can't call union of functions\r\n // error msg in TS3.3 and up: record.v not assignable to never\r\n}\r\n```\r\n\r\n* We want to be able to feed the callback with the original value; but now `v` is a union type and `f`'s parameter type is an intersection; that's not precise for `v`, and that intersection now only accepts `never`.\r\n* People have speculated that maybe we need existential types so that we can say \"this function takes whatever type `v` has\" and can feed it through.\r\n* Can try to re-model this in the form of a re-indexed mapped type.\r\n\r\n ```ts\r\n interface TypeMap {\r\n \"n\": number;\r\n \"s\": string;\r\n \"b\": boolean;\r\n }\r\n\r\n type UnionRecord\u003cP extends keyof TypeMap> = { [K in P}]: {\r\n kind: K;\r\n v: TypeMap[K];\r\n f: (p: TypeMap[K]) => void;\r\n }\r\n }[K];\r\n\r\n function processRecord\u003cK extends keyof TypeMap>(record: UnionRecord\u003cK>) {\r\n record.f(record.v);\r\n }\r\n ```\r\n* With some improvements of inference and apparent types, we can enable most of these cases - 2 improvements on the scale of what feel like bug fixes.\r\n * First is inference to the IIFE-like mapped object pattern from above.\r\n * Second is how we present the apparent members of certain types when you index into an already-instantiated mapped object type (a \"table type\") with some generic key.\r\n * `{ [P in K]: Foo\u003cP> }[X] => Foo\u003cX>`\r\n * Does that mean that if you *aren't* using a type that was declared as a mapped type, then we won't get a more precise type?\r\n * Yes, if you leave off types on these objects.\r\n * I guess we don't have an easy way to correlate.\r\n * We could *try* to do something there...but that's a bit of a stretch.\r\n* This is a weird pattern. Would like to not have to teach people to write this.\r\n\r\n# Modules Migration Status Update\r\n\r\nhttps://github.com/microsoft/TypeScript/pull/46567\r\n\r\n* A lot of time running tests.\r\n* A lot of time is going into getters for every single binding.\r\n* Had TypeScript generate to CJS, had esbuild run on top of that.\r\n* Swapped TS to generate ESM, and esbuild generates the same sorts of bindings - so no optimization there.\r\n* 25 minutes to run the full tests! Thanks to the multiple levels of indirections of calling functions.\r\n* Could switch to ES3 emit to avoid accessors.\r\n* Also could switch to native ESM emit.\r\n * No telling how slow ESM live bindings would be.\r\n* Could avoid indirect barrel imports.\r\n* Looked at bundler front-ends that are largely esbuild wrappers.\r\n * But these tend to push for the optimized build to use Rollup.\r\n* \\[\\[Whole discussion on what the right shipping format and layout to send.]]\r\n* Dogfooding with modules showed us just how slow this is.\r\n * Even getting complaints on tslib: https://github.com/microsoft/tslib/issues/165\r\n* Conclusion\r\n * Investigate the `__createBindings` issue.\r\n * Investigate alternative bundlers.\r\n\r\n# Ensuring Modules Conform to a Type\r\n\r\nhttps://github.com/microsoft/TypeScript/issues/38511\r\n\r\n* Lots of people would like to be able to ensure \"this file has this sort of shape.\"\r\n * Then \"I would like this folder to describe this shape\".\r\n* `export implements SomeType` that \r\n* PR suggests everything should be contextually typed.\r\n* You can emulate this today with a self-import.\r\n * Without contextual typing, this is possibly just sugar that saves you 2 lines. Maybe not as compelling.\r\n* This links to typing default exports - is that the real feature?\r\n* Out of time - revisit in the new year.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2021-12-14T18:47:21Z","url":"https://github.com/microsoft/TypeScript/issues/47151"}
| 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:5221b5d9-0243-0737-940d-a60c62358abd |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB8A:F7C4C:189CEEF:20F43A4:6B01518D |
| html-safe-nonce | 76669432c32371974c3ad667e51b7a114da87d9d2d01185732d52613ff03dc7c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjhBOkY3QzRDOjE4OUNFRUY6MjBGNDNBNDo2QjAxNTE4RCIsInZpc2l0b3JfaWQiOiIxOTk0MzI3Nzk1MDU2ODQ4NzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 38332600d2cd0aae0859b874a2c02aaca86ea517b3d719700404d14311b62d80 |
| hovercard-subject-tag | issue:1080098761 |
| 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/47151/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bb0f5b0ecfb63a79dbf5eacb285b7dd7d2d1a4eba684a0b5fc4d4d4884ac3f0d/microsoft/TypeScript/issues/47151 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bb0f5b0ecfb63a79dbf5eacb285b7dd7d2d1a4eba684a0b5fc4d4d4884ac3f0d/microsoft/TypeScript/issues/47151 |
| og:image:alt | "Correlated Union Types" #30581 type NumberRecord = { kind: "n", v: number, f: (v: number) => void }; type StringRecord = { kind: "s", v: string, f: (v: string) => void }; type BooleanRecord = { ki... |
| 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