Title: Design Meeting Notes, 11/2/2018 · Issue #28326 · microsoft/TypeScript · GitHub
Open Graph Title: Design Meeting Notes, 11/2/2018 · Issue #28326 · microsoft/TypeScript
X Title: Design Meeting Notes, 11/2/2018 · Issue #28326 · microsoft/TypeScript
Description: Generic object spread and spread types (continued) #10727 #21316 (comment) #28234 Back in #10727, we speculated that we could have a new kind of type to describe the behavior of spread on generic types. Seemed pretty complicated to come ...
Open Graph Description: Generic object spread and spread types (continued) #10727 #21316 (comment) #28234 Back in #10727, we speculated that we could have a new kind of type to describe the behavior of spread on generic t...
X Description: Generic object spread and spread types (continued) #10727 #21316 (comment) #28234 Back in #10727, we speculated that we could have a new kind of type to describe the behavior of spread on generic t...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/28326
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Design Meeting Notes, 11/2/2018","articleBody":"# Generic object spread and spread types (continued)\r\n\r\n#10727\r\n\r\nhttps://github.com/Microsoft/TypeScript/pull/21316#issuecomment-359574388\r\n\r\nhttps://github.com/Microsoft/TypeScript/pull/28234\r\n\r\n* Back in #10727, we speculated that we could have a new kind of type to describe the behavior of spread on generic types.\r\n* Seemed pretty complicated to come up with a new rules on higher order spread types so we waited on it.\r\n* Now that our type system has become pretty rich, we started wondering whether we could start to describe spread types in terms of conditional types and mapped types.\r\n* We can kind of do that, but there are certain caveats: our spread functionality tries to guess the \"right\" behavior to reflect the runtime.\r\n* We don't copy methods, we avoid set-only accessors, whatever.\r\n* Now if we want to do this in a higher-order sense (i.e. on generics), you need a way to select the keys that spread would actually copy those over.\r\n* So we thought about an `own` operator, but then you get into some unintuitive cases. For example, you'd think that for the following:\r\n\r\n ```ts\r\n function foo\u003cT>(obj1: T, obj2: T) {\r\n return { ...obj1, ...obj2 };\r\n }\r\n ```\r\n\r\n you'd get something assignable to a `T`. But no, instead you'd get something like a `Spread\u003cOwn\u003cT>, Own\u003cT>>` - which is not a `T`, and is not even an `Own\u003cT>` without some extra work. So this is not great.\r\n* Up until now, `Object.assign` just returned intersections.\r\n * But spreads have almost identical semantics to `Object.assign`!\r\n * While it's not correct to return intersections, by and large it's been good enough.\r\n * So what we do now is that when you have a \"zero-order\" type (i.e. a non-generic type), we just do what we do today by constructing a new object type; but if you have a generic type, we'll stop and intersect with the current run of spreads.\r\n * So `...{ x: 100}, ...{ y: \"hello\" }, ...z` where `z` has type `T` is `{ x: number, y: string } & T`.\r\n\r\n# Generic object rest\r\n\r\n* The natural question arises: what about object rest.\r\n* With #28312, if `obj` has type `T extends { foo: string }`, for the following code:\r\n\r\n ```ts\r\n function f\u003cT extends { foo: string }>(obj: T) {\r\n let { foo, ...rest } = obj;\r\n return rest;\r\n }\r\n ```\r\n\r\n now `f` returns the type `Pick\u003cT, Exclude\u003ckeyof T, \"foo\">>`.\r\n* There was some work that needed to be done with symbols.\r\n * Wait, symbols aren't enumerable.\r\n * Does that matter?\r\n * \\[\\[Discussion]]\r\n* What about the higher order components which are one of the most in-demand use-cases here?\r\n * Doesn't seem to \"work\" right\r\n\r\n ```ts\r\n function excludeTag\u003c\r\n T extends { tag: string } & U,\r\n U extends>(\r\n obj: T) {\r\n let { foo, ...rest } = obj;\r\n let blah: U = rest; // error!\r\n }\r\n ```\r\n* People might try to use `Pick\u003cT, Exclude\u003ckeyof T, keyof U>>` and it still won't work.\r\n* Sounds like we need subtraction types!\r\n * Even though we kind of sort of have them with `Exclude`.\r\n* \\[\\[Discussion about subtraction types and negated types]]\r\n\r\n# Partial Type Argument Inference (revisited)\r\n\r\n#26349\r\n\r\n* We put out #26349 back in August\r\n* ~6 weeks ago when we last talked about partial type argument inference, we decided not to do anything since we couldn't pick a sigil.\r\n* Recently Flow implemented the feature and picked the `_` character.\r\n* This is the second-most voted PR on our repo.\r\n* Seems like there are legitimate use-cases and C# is looking at this; so what's the sigil?\r\n* Problem with `_` is that it's a legitimate use-case\r\n * BigTSQuery says that there are a couple of uses of `_` but explicit type arguments are rare; so contextually reserving it is definitely overkill.\r\n* Conclusion: \r\n\r\n# Structurally identical-looking `Derived\u003cT>` not assignable to `Base\u003cT>`\r\n\r\nhttps://github.com/Microsoft/TypeScript/issues/27984\r\n\r\n* We fixed the specific issue, but there are other issues here.\r\n\r\n# Built-in base configs\r\n\r\nhttps://github.com/Microsoft/TypeScript/issues/28147\r\n\r\n* Do we want to ship any default configs ourselves.\r\n * We can ship a set of defaults for well-known workloads (e.g. mixed JS & TS)\r\n* But your defaults for Babel aren't related to defaults for strictness.\r\n * So now you need multiple inheritance to combine multiple tsconfigs!?\r\n* Lots of potential to break.\r\n* Scaffolding tools already do it all for you anyway.\r\n* Not clear if it's any more discoverable than the options themselves.","author":{"url":"https://github.com/DanielRosenwasser","@type":"Person","name":"DanielRosenwasser"},"datePublished":"2018-11-03T01:00:37Z","url":"https://github.com/microsoft/TypeScript/issues/28326"}
| 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:d663b1de-faf9-e2d7-cb08-32f7fc2ea189 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C718:291B58:23B42D9:2D4DF4D:6B01BD35 |
| html-safe-nonce | 25b95ae02b798c448419882a0c8366ff2b6860677e97a472b9fa5b65f23f6cfd |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDNzE4OjI5MUI1ODoyM0I0MkQ5OjJENERGNEQ6NkIwMUJEMzUiLCJ2aXNpdG9yX2lkIjoiODA3MjI0ODc4NTMxMDQzMjU2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 2f0e71e36f0ee56f79fd9bbaa027dff59047f54a20a1fcf7eaf22a585aa85f40 |
| hovercard-subject-tag | issue:377008872 |
| 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/28326/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9a37593cae928bccaab9011316c8c0cb6fc6873eeec1b59b83849e85deaeb738/microsoft/TypeScript/issues/28326 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9a37593cae928bccaab9011316c8c0cb6fc6873eeec1b59b83849e85deaeb738/microsoft/TypeScript/issues/28326 |
| og:image:alt | Generic object spread and spread types (continued) #10727 #21316 (comment) #28234 Back in #10727, we speculated that we could have a new kind of type to describe the behavior of spread on generic t... |
| 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