René's URL Explorer Experiment


Title: Feature Request: Readonly should remove mutable methods · Issue #35313 · microsoft/TypeScript · GitHub

Open Graph Title: Feature Request: Readonly should remove mutable methods · Issue #35313 · microsoft/TypeScript

X Title: Feature Request: Readonly should remove mutable methods · Issue #35313 · microsoft/TypeScript

Description: Search Terms readonly, as const, Readonly, Suggestion Readonly to work the way Readonly does without having to create something like ReadonlyArray, ReadonlySet, etc... I would love it if the Readonly mapped type could exclude any...

Open Graph Description: Search Terms readonly, as const, Readonly, Suggestion Readonly to work the way Readonly does without having to create something like ReadonlyArray, ReadonlySet, etc... I would love it if the R...

X Description: Search Terms readonly, as const, Readonly, Suggestion Readonly to work the way Readonly<T[]> does without having to create something like ReadonlyArray, ReadonlySet, etc... I would love it if...

Opengraph URL: https://github.com/microsoft/TypeScript/issues/35313

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Feature Request: Readonly\u003cT> should remove mutable methods","articleBody":"## Search Terms\r\n\r\nreadonly, as const, Readonly\u003cT>,\r\n\r\n## Suggestion\r\n\r\nReadonly\u003cT> to work the way Readonly\u003cT[]> does without having to create something like ReadonlyArray\u003cT>, ReadonlySet\u003cT>, etc...\r\n\r\n\r\nI would love it if the `Readonly\u003cT>` mapped type could exclude any method marked as `readonly` or maybe `as cosnt` or something similar.\r\n\r\n## Use Cases\r\n\r\nAt the moment I have to do this:\r\n\r\n```typescript\r\nclass Vector2 {\r\n    public constructor(\r\n        public x: number,\r\n        public x: number,\r\n    ) {}\r\n\r\n    public add(other: ReadonlyVector2): Vector2 {\r\n        return this.clone().addInPlace(other);\r\n    }\r\n\r\n    public addInPlace(other: ReadonlyVector2): this {\r\n        this.x += other.x;\r\n        this.y += other.y;\r\n        return this;\r\n    }\r\n\r\n    public clone(): Vector2 {\r\n        return new Vector2(this.x, this.y);\r\n    }\r\n}\r\n\r\ninterface ReadonlyVector2 {\r\n    readonly x: number;\r\n    readonly y: number;\r\n    add(other: ReadonlyVector2): Vector2;\r\n    clone(): Vector2;\r\n}\r\n```\r\n\r\nThis gets very boring with a lot of types, also it's error prone. I could forget to add something to the interface, or worse I could accidentally add something that is mutable.\r\n\r\nI can currently do `method(this: Readonly\u003cthis>) {...}`, which is helpful, but doesn't stop me calling mutable methods on the type.\r\n\r\nInside a marked method you would be unable to mutate the state of member variables and you would unable to call other unmarked methods.\r\n\r\nThis would also allow you to remove the special case of `Readonly\u003cT[]>`. The mutable methods of arrays could be marked with whatever syntax is decided and then `Readonly\u003cT[]>` would just work like any other `Readonly\u003cT>`. Currently I don't bother using `Readonly\u003cT>` since it doesn't really help with anything except C style POD types. \r\n\r\n## Examples\r\n\r\n```typescript\r\nclass Vector2 {\r\n    public constructor(\r\n        public x: number,\r\n        public x: number,\r\n    ) {}\r\n\r\n    public readonly add(other: Readonly\u003cVector2>): Vector2 {\r\n        return this.clone().addInPlace(other);\r\n    }\r\n\r\n    public addInPlace(other: Readonly\u003cVector2>): this {\r\n        this.x += other.x;\r\n        this.y += other.y;\r\n        return this;\r\n    }\r\n\r\n    public const clone(): Vector2 {\r\n        return new Vector2(this.x, this.y);\r\n    }\r\n}\r\n```\r\n\r\n## Checklist\r\n\r\nMy suggestion meets these guidelines:\r\n\r\n* [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code\r\n* [x] This wouldn't change the runtime behavior of existing JavaScript code\r\n* [x] This could be implemented without emitting different JS based on the types of the expressions\r\n* [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)\r\n* [x] This feature would agree with the rest of [TypeScript's Design Goals](https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals).\r\n","author":{"url":"https://github.com/rope-hmg","@type":"Person","name":"rope-hmg"},"datePublished":"2019-11-23T18:04:20Z","url":"https://github.com/microsoft/TypeScript/issues/35313"}

react-profiling0
react-import-mapreact,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-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:8cffb810-e120-e7ff-70cf-dfcdd72b021a
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-idAA84:BD02F:F01E14:14B73BE:6AFBF55E
html-safe-noncea50dd6928c5778c2350bf246a9c3f8d23880da589b8e8f8ed04829e09a925fd2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQTg0OkJEMDJGOkYwMUUxNDoxNEI3M0JFOjZBRkJGNTVFIiwidmlzaXRvcl9pZCI6IjE3OTY4MzM4NjEwOTUzODg1MTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac3abae34056641dc05e64d0a8768d59754aa0a5327fefa1918cc29bbc7be39275
hovercard-subject-tagissue:527588654
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/microsoft/TypeScript/35313/issue_layout
twitter:imagehttps://opengraph.githubassets.com/94ed104201585980fd2684bcc389a536b05ddb246c916e030f084f78928f22cf/microsoft/TypeScript/issues/35313
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/94ed104201585980fd2684bcc389a536b05ddb246c916e030f084f78928f22cf/microsoft/TypeScript/issues/35313
og:image:altSearch Terms readonly, as const, Readonly, Suggestion Readonly to work the way Readonly does without having to create something like ReadonlyArray, ReadonlySet, etc... I would love it if the R...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamerope-hmg
hostnamegithub.com
expected-hostnamegithub.com
Nonefa74413a1d84dac536fcca0740780bcbd3207bafec0e51873b73ff8e8cca032f
turbo-cache-controlno-preview
go-importgithub.com/microsoft/TypeScript git https://github.com/microsoft/TypeScript.git
octolytics-dimension-user_id6154722
octolytics-dimension-user_loginmicrosoft
octolytics-dimension-repository_id20929025
octolytics-dimension-repository_nwomicrosoft/TypeScript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id20929025
octolytics-dimension-repository_network_root_nwomicrosoft/TypeScript
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releaseb3b5633a74535d9c23385512d534c66c8fde1907
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/35313#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F35313
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F35313
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=microsoft%2FTypeScript
Reloadhttps://github.com/microsoft/TypeScript/issues/35313
Reloadhttps://github.com/microsoft/TypeScript/issues/35313
Reloadhttps://github.com/microsoft/TypeScript/issues/35313
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests335 (335)https://github.com/microsoft/TypeScript/pulls
Actionshttps://github.com/microsoft/TypeScript/actions
Projectshttps://github.com/microsoft/TypeScript/projects
Wikihttps://github.com/microsoft/TypeScript/wiki
Security and qualityhttps://github.com/microsoft/TypeScript/security
Insightshttps://github.com/microsoft/TypeScript/pulse
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35313
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35313
Feature Request: Readonly should remove mutable methodshttps://github.com/microsoft/TypeScript/issues/35313#top
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Nov 23, 2019https://github.com/microsoft/TypeScript/issues/35313#issue-527588654
TypeScript's Design Goalshttps://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals
https://github.com/fatcerberus
Bruce Pascoe (fatcerberus)https://github.com/fatcerberus
on Nov 23, 2019https://github.com/microsoft/TypeScript/issues/35313#issuecomment-557820420
https://github.com/AnyhowStep
AnyhowStephttps://github.com/AnyhowStep
on Nov 23, 2019https://github.com/microsoft/TypeScript/issues/35313#issuecomment-557829808
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Nov 24, 2019https://github.com/microsoft/TypeScript/issues/35313#issuecomment-557892740
https://github.com/fatcerberus
Bruce Pascoe (fatcerberus)https://github.com/fatcerberus
on Nov 24, 2019https://github.com/microsoft/TypeScript/issues/35313#issuecomment-557897377
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Nov 24, 2019https://github.com/microsoft/TypeScript/issues/35313#issuecomment-557901845
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Nov 26, 2019https://github.com/microsoft/TypeScript/issues/35313#issuecomment-558700472
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Nov 27, 2019https://github.com/microsoft/TypeScript/issues/35313#issuecomment-559110193
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
on Jan 7, 2020https://github.com/microsoft/TypeScript/issues/35313#event-2928581274
https://github.com/kwasimensah
kwasimensahhttps://github.com/kwasimensah
on Apr 23, 2020https://github.com/microsoft/TypeScript/issues/35313#issuecomment-618120209
https://github.com/OldStarchy
OldStarchyhttps://github.com/OldStarchy
on Sep 11, 2021https://github.com/microsoft/TypeScript/issues/35313#issuecomment-917314651
https://stackoverflow.com/a/751783https://stackoverflow.com/a/751783
#24509https://github.com/microsoft/TypeScript/issues/24509
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Dec 23, 2021https://github.com/microsoft/TypeScript/issues/35313#issuecomment-1000262879
https://user-images.githubusercontent.com/2173098/147238723-328d90fb-d4ad-443a-90bf-fc3454990f58.png
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Dec 23, 2021https://github.com/microsoft/TypeScript/issues/35313#issuecomment-1000280769
OldStarchyhttps://github.com/OldStarchy
https://github.com/viridia
Talin (viridia)https://github.com/viridia
on Apr 4, 2023https://github.com/microsoft/TypeScript/issues/35313#issuecomment-1496667275
https://github.com/rope-hmg
Hector Maddock-Greene (rope-hmg)https://github.com/rope-hmg
on Apr 19, 2023https://github.com/microsoft/TypeScript/issues/35313#issuecomment-1515090802
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/35313
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/35313
Awaiting More FeedbackThis means we'd like to hear from more people who would be helped by this featurehttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Awaiting%20More%20Feedback%22
SuggestionAn idea for TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Suggestion%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.