Title: Suggestion: readonly constructor parameters · Issue #7590 · microsoft/TypeScript · GitHub
Open Graph Title: Suggestion: readonly constructor parameters · Issue #7590 · microsoft/TypeScript
X Title: Suggestion: readonly constructor parameters · Issue #7590 · microsoft/TypeScript
Description: I've been using the new readonly properties feature (#6532) and have found it to be a very productive alternative to using getters or getWhatever() functions, or as is often the case, simply doing nothing to enforce read-only properties....
Open Graph Description: I've been using the new readonly properties feature (#6532) and have found it to be a very productive alternative to using getters or getWhatever() functions, or as is often the case, simply doing ...
X Description: I've been using the new readonly properties feature (#6532) and have found it to be a very productive alternative to using getters or getWhatever() functions, or as is often the case, simply do...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/7590
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Suggestion: readonly constructor parameters","articleBody":"I've been using the new `readonly` properties feature (#6532) and have found it to be a very productive alternative to using getters or `getWhatever()` functions, or as is often the case, simply doing nothing to enforce read-only properties. However I'm really yearning for the ability to mark constructor parameters as `readonly`.\n\nIn 1.8 a common pattern for me is to write classes where all properties are public and readonly like so:\n\n``` typescript\nexport class Foo {\n constructor(public bar: number,\n public baz: number) {}\n}\n\n```\n\nBut now with `readonly` I'm missing out unless I rewrite the above code to:\n\n``` typescript\nexport class Foo {\n public readonly bar: number;\n public readonly baz: number;\n\n constructor(bar: number, baz: number) {\n this.bar = bar;\n this.baz = baz;\n }\n}\n```\n\nWhich is pretty cumbersome. What I'd really like to be able to write is:\n\n``` typescript\nexport class Foo {\n constructor(public readonly bar: number,\n public readonly baz: number) {}\n}\n```\n\nRight now I'm worried about hitting 2.0 and having to rewrite all my constructors just to take advantage of `readonly`. Because it's an advantage I definitely want to have.\n","author":{"url":"https://github.com/jahewson","@type":"Person","name":"jahewson"},"datePublished":"2016-03-19T01:05:43Z","url":"https://github.com/microsoft/TypeScript/issues/7590"}
| 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:6c2831a5-28f4-eda2-5d70-1884578481af |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CCD0:3D97C8:3648C8:4A5139:6B00C6EF |
| html-safe-nonce | cfa28ac0945e37ffb93414e8fee24ec812008840bb0b520efd1ac5775a455962 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQ0QwOjNEOTdDODozNjQ4Qzg6NEE1MTM5OjZCMDBDNkVGIiwidmlzaXRvcl9pZCI6IjE5MzM3MDQ1NzMyMTQ1NzQzMTkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 60793e7e66b9c72399effcde5ae5ad116cb7c13fa54748048179be5a8e3acd08 |
| hovercard-subject-tag | issue:142010526 |
| 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/7590/issue_layout |
| twitter:image | https://opengraph.githubassets.com/62bd8980bdaae8b5a4dcd97372c0debaf4a259447f5c5726bbf901e59f856ef7/microsoft/TypeScript/issues/7590 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/62bd8980bdaae8b5a4dcd97372c0debaf4a259447f5c5726bbf901e59f856ef7/microsoft/TypeScript/issues/7590 |
| og:image:alt | I've been using the new readonly properties feature (#6532) and have found it to be a very productive alternative to using getters or getWhatever() functions, or as is often the case, simply doing ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | jahewson |
| hostname | github.com |
| expected-hostname | github.com |
| None | 98dc00e171c204462a6f367482a0f8c3c6b5dbca99cd7390e82d2df49ce096e4 |
| 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 | ef013399cf0a3c324bea644a685d7c1e0f06b5b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width