Title: TypeScript should have "Records" like C#7 · Issue #10910 · microsoft/TypeScript · GitHub
Open Graph Title: TypeScript should have "Records" like C#7 · Issue #10910 · microsoft/TypeScript
X Title: TypeScript should have "Records" like C#7 · Issue #10910 · microsoft/TypeScript
Description: Proposal Typescript should be able to generate immutable objects with accessor properties and value semantics, similar to the "records" proposal for C# 7.0 Rationale Currently I have to write a lot of boilerplate code to create an object...
Open Graph Description: Proposal Typescript should be able to generate immutable objects with accessor properties and value semantics, similar to the "records" proposal for C# 7.0 Rationale Currently I have to write a lot...
X Description: Proposal Typescript should be able to generate immutable objects with accessor properties and value semantics, similar to the "records" proposal for C# 7.0 Rationale Currently I have to w...
Opengraph URL: https://github.com/microsoft/TypeScript/issues/10910
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"TypeScript should have \"Records\" like C#7","articleBody":"# Proposal\n\nTypescript should be able to generate immutable objects with accessor properties and value semantics, similar to the \"records\" proposal for C# 7.0\n# Rationale\n\nCurrently I have to write a lot of boilerplate code to create an object with accessor properties and value semantics. I think this can easily be streamlined by the TypeScript compiler.\n# Example of what I have to write currently\n\n```\nclass Person {\n private _firstName: string;\n private _lastName: string;\n\n constructor(firstName: string = null, lastName: string = null) {\n this._firstName = firstName;\n this._lastName = lastName;\n }\n\n public get firstName(): string {\n return this._firstName;\n }\n\n public get lastName(): string {\n return this._lastName;\n }\n\n public equals(other: Person): boolean {\n return other !== void 0\n && other !== null\n && this._firstName === other._firstName\n && this._lastName === other._lastName;\n }\n}\n```\n# What I would like to write in future\n\n```\nclass Person {\n constructor(\n public get firstName: string = null,\n public get lastName: string = null) { \n }\n}\n```\n\nNote the use of **get** in the constructor\n\nEither of the examples above **should** produce this (the top example **did** produce this)\n\n```\nvar Person = (function () {\n function Person(firstName, lastName) {\n if (firstName === void 0) { firstName = null; }\n if (lastName === void 0) { lastName = null; }\n this._firstName = firstName;\n this._lastName = lastName;\n }\n Object.defineProperty(Person.prototype, \"firstName\", {\n get: function () {\n return this._firstName;\n },\n enumerable: true,\n configurable: true\n });\n Object.defineProperty(Person.prototype, \"lastName\", {\n get: function () {\n return this._lastName;\n },\n enumerable: true,\n configurable: true\n });\n Person.prototype.equals = function (other) {\n return other !== void 0\n && other !== null\n && this._firstName === other._firstName\n && this._lastName === other._lastName;\n };\n return Person;\n}());\n\n```\n","author":{"url":"https://github.com/MrMatthewLayton","@type":"Person","name":"MrMatthewLayton"},"datePublished":"2016-09-14T10:45:12Z","url":"https://github.com/microsoft/TypeScript/issues/10910"}
| 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:d49f0471-85ad-c143-1426-692765802003 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82BC:E2D7:75D979:A0E6B8:6AFBC902 |
| html-safe-nonce | 1c5e2fe076eae1538199bc7da5ecb7d9cd28447f1c1b3608d207e8e27c1ed041 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkJDOkUyRDc6NzVEOTc5OkEwRTZCODo2QUZCQzkwMiIsInZpc2l0b3JfaWQiOiIyNDExMDg3MjA3NDU3MzQzNzQ2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b6aec5d6a134b5664fddbf63cc63e5a0154ae238446bb7ac28ffe48709d801e2 |
| hovercard-subject-tag | issue:176874543 |
| 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/10910/issue_layout |
| twitter:image | https://opengraph.githubassets.com/9651c13d9c32b2c0d150433bc21610bc241fbec58eb7c76ff5b7fdd84f67c36f/microsoft/TypeScript/issues/10910 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/9651c13d9c32b2c0d150433bc21610bc241fbec58eb7c76ff5b7fdd84f67c36f/microsoft/TypeScript/issues/10910 |
| og:image:alt | Proposal Typescript should be able to generate immutable objects with accessor properties and value semantics, similar to the "records" proposal for C# 7.0 Rationale Currently I have to write a lot... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | MrMatthewLayton |
| hostname | github.com |
| expected-hostname | github.com |
| None | d440bda0d812801778b27bfe9f7c1ce9ff22420c73f6f95150c4fcbca311c50b |
| 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 | 2c43021aed8695990c86c0eaaedc600bfeffec36 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width