Title: Partial Types · Issue #11233 · microsoft/TypeScript · GitHub
Open Graph Title: Partial Types · Issue #11233 · microsoft/TypeScript
X Title: Partial Types · Issue #11233 · microsoft/TypeScript
Description: This is a proposal for #4889 and a variety of other issues. Use Cases Many libraries, notably React, have a method which takes an object and updates corresponding fields on some other object on a per-key basis. It looks like this functio...
Open Graph Description: This is a proposal for #4889 and a variety of other issues. Use Cases Many libraries, notably React, have a method which takes an object and updates corresponding fields on some other object on a p...
X Description: This is a proposal for #4889 and a variety of other issues. Use Cases Many libraries, notably React, have a method which takes an object and updates corresponding fields on some other object on a p...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/11233
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Partial Types","articleBody":"This is a proposal for #4889 and a variety of other issues.\n## Use Cases\n\nMany libraries, notably React, have a method which takes an object and updates corresponding fields on some other object on a per-key basis. It looks like this\n\n``` ts\nfunction setState\u003cT>(target: T, settings: ??T??) {\n // ...\n}\nlet obj = { a: 2, b: \"ok\", c: [1] };\nsetState(obj, { a: 4 }); // Desired OK\nsetState(obj, { a: \"nope\"}); // Desired error\nsetState(obj, { b: \"OK\", c: [] }); // Desired OK\nsetState(obj, { a: 1, d: 100 }); // Desired error\nsetState(obj, window); // Desired error\n```\n## Observations\n- The update is rarely recursive (an exception is Mongo's `query`); this is a \"shallow\" operation\n- It's not desirable to allow \"new\" properties to appear\n- We're not looking for a _supertype_ of some type (due to the non-recursive nature)\n## Unary `partial T` operator\n\nA type `partial T` behaves as follows:\n1. Its properties are the same as the properties of `T`, except that those properties are now optional\n2. A `S` type is only assignable to type `partial T` if `S` has at least one property in common with `T`\n - Otherwise regular structural subtype/assignability rules apply\n3. The type `partial (T | U)` is equivalent to `(partial T) | (partial U)`\n4. The type `partial (T & U)` does not expand (this would interact poorly with rule 2)\n5. Any type `T` is always a subtype of `partial T`\n6. The type `partial T` is equivalent to `T` if `T` is `any`, `never`, `null`, or `undefined`\n\nMore thoughts to come later, likely\n","author":{"url":"https://github.com/RyanCavanaugh","@type":"Person","name":"RyanCavanaugh"},"datePublished":"2016-09-28T23:53:24Z","url":"https://github.com/microsoft/TypeScript/issues/11233"}
| 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:9d7c5714-6cea-afe0-4531-02b07fecc3b6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8CC6:15BA57:E161C:13B4EA:6AFBDA99 |
| html-safe-nonce | 2635969bf12e3c73e0c8843ccffe7864e47a87430b5137e28a9c7d799af6df3b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4Q0M2OjE1QkE1NzpFMTYxQzoxM0I0RUE6NkFGQkRBOTkiLCJ2aXNpdG9yX2lkIjoiMTExMjY3ODMzNzE0ODA4Mjg0MSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 22bcf2765e8458eee864050251edf63b67faf917856a259ad5fec0902fbdec08 |
| hovercard-subject-tag | issue:179920279 |
| 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/11233/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2fa0d1af1aa7a455cb15584b3b5f725ba46dd2a384e463115b84452282c19830/microsoft/TypeScript/issues/11233 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2fa0d1af1aa7a455cb15584b3b5f725ba46dd2a384e463115b84452282c19830/microsoft/TypeScript/issues/11233 |
| og:image:alt | This is a proposal for #4889 and a variety of other issues. Use Cases Many libraries, notably React, have a method which takes an object and updates corresponding fields on some other object on a p... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | RyanCavanaugh |
| hostname | github.com |
| expected-hostname | github.com |
| None | 18742cb872ec73544356e60359266b67aafece70c4ce008042e06227924cdd07 |
| 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 | 820be804f18e1ef3940bd74a00d41d73d02e2b91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width