Title: add a constraint for immutable types · Issue #14909 · microsoft/TypeScript · GitHub
Open Graph Title: add a constraint for immutable types · Issue #14909 · microsoft/TypeScript
X Title: add a constraint for immutable types · Issue #14909 · microsoft/TypeScript
Description: say, i have a generic function that by design requires that its parameters may only take immutable arguments, i wish i could get such guarantee from TS by declaring my function as follows: function doThings
Open Graph Description: say, i have a generic function that by design requires that its parameters may only take immutable arguments, i wish i could get such guarantee from TS by declaring my function as follows: function...
X Description: say, i have a generic function that by design requires that its parameters may only take immutable arguments, i wish i could get such guarantee from TS by declaring my function as follows: function...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/14909
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"add a constraint for immutable types","articleBody":"say, i have a generic function that by design requires that its parameters may only take immutable arguments, i wish i could get such guarantee from TS by declaring my function as follows:\r\n\r\n```typescript\r\nfunction doThings\u003creadonly T>(value: T): Result\u003cT> {\r\n // ...\r\n}\r\n```\r\nas far as how to make an interface immutable:\r\n```typescript\r\nreadonly interface Point {\r\n readonly x: number;\r\n readonly y: number;\r\n}\r\n```\r\n\r\nso the problem being solve here is to make sure that the caller won't mutate the argument after it is passed to the function\r\n\r\n**simple use case**: a hash-based data container, which calculates a hash of a given value, and will store it at that hash, and it all will work until the value is mutated outside and tha stored hash is no longer valid, so the container doesn't really work anymore\r\n\r\n**another use case**: a cache or object pool or any other situation when there are many parties involved in taking hold of the same object, which must be guaranteed from being mutated by one party to prevent spooky action at a distance for all other parties\r\n","author":{"url":"https://github.com/zpdDG4gta8XKpMCd","@type":"Person","name":"zpdDG4gta8XKpMCd"},"datePublished":"2017-03-29T14:02:23Z","url":"https://github.com/microsoft/TypeScript/issues/14909"}
| 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:3cc704a3-ec2f-17dc-6aa1-37364621b033 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 98BE:92094:DB9703:12EB5EE:6AFBF0A8 |
| html-safe-nonce | 77cff56b5eee23080cd9a4c987e954dc770a8cc8549e3b1f39b5acc799942fd5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OEJFOjkyMDk0OkRCOTcwMzoxMkVCNUVFOjZBRkJGMEE4IiwidmlzaXRvcl9pZCI6IjM0Mjc4ODA1OTU0OTU4NDE5NjAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 36f05b5b3f369958702f85b6100e7c81afda19fa18da08ddc478cb0656eaa78b |
| hovercard-subject-tag | issue:217886045 |
| 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/14909/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8794a4875c8b0188f27009fd71e6f92c38e52990c11e504f9f66d964d864cbef/microsoft/TypeScript/issues/14909 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8794a4875c8b0188f27009fd71e6f92c38e52990c11e504f9f66d964d864cbef/microsoft/TypeScript/issues/14909 |
| og:image:alt | say, i have a generic function that by design requires that its parameters may only take immutable arguments, i wish i could get such guarantee from TS by declaring my function as follows: function... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | zpdDG4gta8XKpMCd |
| hostname | github.com |
| expected-hostname | github.com |
| None | fa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f |
| 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 | b3b5633a74535d9c23385512d534c66c8fde1907 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width