Title: Design Meeting Notes, 12/14/2018 · Issue #29033 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 12/14/2018 · Issue #29033 · microsoft/TypeScript
X Title: Design Meeting Notes, 12/14/2018 · Issue #29033 · microsoft/TypeScript
Description: Control Flow Analysis for Destructuring Assignments #28792 let { x } = obj; // *should* be equivalent to let x = obj.x; And this holds for any level of nesting. let { x: { y } } = obj; // *should* be equivalent to let y = obj.x.y; And th...
Open Graph Description: Control Flow Analysis for Destructuring Assignments #28792 let { x } = obj; // *should* be equivalent to let x = obj.x; And this holds for any level of nesting. let { x: { y } } = obj; // *should* ...
X Description: Control Flow Analysis for Destructuring Assignments #28792 let { x } = obj; // *should* be equivalent to let x = obj.x; And this holds for any level of nesting. let { x: { y } } = obj; // *should* ...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/29033
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 12/14/2018","articleBody":"# Control Flow Analysis for Destructuring Assignments\r\n\r\n#28792\r\n\r\n```ts\r\nlet { x } = obj;\r\n\r\n// *should* be equivalent to\r\n\r\nlet x = obj.x;\r\n```\r\n\r\nAnd this holds for any level of nesting.\r\n\r\n```ts\r\nlet { x: { y } } = obj;\r\n\r\n// *should* be equivalent to\r\n\r\nlet y = obj.x.y;\r\n```\r\n\r\nAnd the same for object pattern assignments\r\n\r\n```ts\r\n({ x } = obj);\r\n\r\n// *should* be equivalent to\r\n\r\nx = obj.x;\r\n```\r\n\r\n* Today, we don't track these assignments as part of control flow analysis.\r\n * Trying to do so is actually pretty complex.\r\n * As a solution, we're considering a new \"synthetic property access\"\r\n\r\n# Unification\r\n\r\n* Consider\r\n\r\n ```ts\r\n function compose\u003cA, B, C>(f1: (x: A) => B, f2: (x: B) => C): (x: A) => C { /*...*/ }\r\n function arrayToList\u003cT>(x: T[]): List\u003cT> { /*...*/ }\r\n function box\u003cU>(x: U): { value: U } { /*...*/ }\r\n function first\u003cW>(xs: List\u003cW>): W { /*...*/ }\r\n ```\r\n\r\n* What if you wanted to write a function that `box`'d a list converted from an array? Ideally you could write the following:\r\n\r\n ```ts\r\n compose(arrayToList, box)\r\n ```\r\n\r\n and you'd get the type `\u003cT>(xs: T[]) => { value: List\u003cT> }`\r\n\r\n * Today the problem is that when our inference process sees no inferences for a type parameter, it infers its upper bound (which is implicitly `{}`).\r\n * Instead, what you really want to do is see that there are *free type variables* that are captured in the output, and attach them to the output type.\r\n * Starting off with this idea comes close. You get `\u003cT, U>(xs: T) => U`, but of course, this doesn't propagate the original structures of inferences. Furthermore, `T` and `U` are unrelated. So what you want to do is unify the type variables during the first inference pass.\r\n* *When* you could do this is tough; you can't just replace the current inference process with unification. No telling what could break. But we can revisit that.\r\n* So saying \"unification would do this\" is fine, but how that happens is glossed over. There's some difficult cases.\r\n* ```\r\n A : T[]\r\n B : List\u003cT>, SomeOtherList\u003cW>\r\n C : W\r\n ```\r\n* Could say we only unify on named types.\r\n * What about object literal types?\r\n * It's a structural type system; y'can't backpedal on that.\r\n* Today we fix type parameters once they're requested in an anonymous function. How does this work with contextual typing?\r\n * Say it's there for single-signature types?\r\n * It's not about overloads.\r\n * Would we need to add type variables for anonymous functions?\r\n * #17428\r\n * Also, building up constraints could get gross:\r\n\r\n ```ts\r\n compose(arrayToList, x => x.get(0));\r\n ```\r\n * Could defer things.\r\n * The type might look gross for users. `{ get(): T }` is not so bad, but imagine a more complex function body.\r\n* When you you're editing, what happens when the anonymous function comes first?\r\n * Hah.\r\n * Same downsides as today.\r\n * Functional users won't be happy with that experience.\r\n * \"Daniel's not wrong\"\r\n * \\[\\[First time anyone's ever said that]]\r\n* Seems like there's a lot of open questions.\r\n\r\n# Call signatures on union types\r\n\r\n#7294\r\n#29011\r\n\r\n* We erred on the safe side much of the time to say that signatures had to be identical.\r\n* In the last release, we expanded this to have signatures that totally subsumed other signatures available to callers.\r\n* When we unified JSX logic with call resolution logic, React users got broken because we were more permissive in React.\r\n* Okay, so we methods available a lot of the time when you have two union types; however, it doesn't work great for methods that take callbacks.\r\n * For example, if you have `xs: string[] | number[]`, trying to call `xs.forEach` is possible, but lambda functions don't undergo contextual typing (one of our inference processes).\r\n * The reason why is that the contextual type is something like `((x: string) => void) & ((y: number) => void)`.\r\n * You'd think that would be fine and in `xs.forEach(a => a)`, `a` would have the type `string | number`, but what instead happens is that `((x: string) => void) & ((y: number) => void)` forms something that looks like an overload list, and lambdas aren't contextually typed by overloads.\r\n* Three solutions:\r\n * Change contextual typing to be contextually typed by overload lists.\r\n * Could come up with an underlying \"intersection signature\" (we have something similar for unions).\r\n * Means there's a difference between contextual typing and relationship checking.\r\n * Take the current fix (#29011) as-is.\r\n * The `forEach` case is still broken, but at least we're better.\r\n* With the intersection signature strategy, what about an intersection where one type has no call signatures, and the other has many?\r\n * You'd have no \"intersection signature\", but a bunch of overloads.\r\n * One thing we didn't do here is try to come up with an intersection signature for multiple overloads; seems like a combinatorial explosion.\r\n* With the overload strategy, what about UX? What about huge overload lists like in the DOM?\r\n* Should we try to remove impossible `never` parameters from these \"synthesized\" signatures?\r\n * Seems like the wrong thing to focus on.\r\n* Out of time - seems like we're leaning towards overloads.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2018-12-14T22:36:33Z","url":"https://github.com/microsoft/TypeScript/issues/29033"}
| 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:1d44ee44-d8e7-ba56-263c-158331fc2b8a |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBB0:29FFA9:5F4E3F:7A8F9F:6B00DD82 |
| html-safe-nonce | f51ee714002aa8fdcbdaaf3719cc4fad11de60711c211772c3a5e1c2c6044451 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkIwOjI5RkZBOTo1RjRFM0Y6N0E4RjlGOjZCMDBERDgyIiwidmlzaXRvcl9pZCI6IjU1MzgxMDkyODkxNDg3Njc2MTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 583e147f854989218f5e89779e2bf67b6d7c3a574218f65e5e1d5e157c077d63 |
| hovercard-subject-tag | issue:391302423 |
| 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/29033/issue_layout |
| twitter:image | https://opengraph.githubassets.com/93341fa9c648fac93fbdc8b3f57e5fcb97758f43951c02d70d3daeebf3c7568f/microsoft/TypeScript/issues/29033 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/93341fa9c648fac93fbdc8b3f57e5fcb97758f43951c02d70d3daeebf3c7568f/microsoft/TypeScript/issues/29033 |
| og:image:alt | Control Flow Analysis for Destructuring Assignments #28792 let { x } = obj; // *should* be equivalent to let x = obj.x; And this holds for any level of nesting. let { x: { y } } = obj; // *should* ... |
| 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 | 043c3f30fbcbe2c6c8e729e10cbbbc90c406546f9fbbb67c648d38f6b7d16daf |
| 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 | 5425dc24e8bd8d6fca9641a12afc984825a43875 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width