René's URL Explorer Experiment


Title: Intersection between separate types with getter and setter does not allow assignment to property · Issue #45122 · microsoft/TypeScript · GitHub

Open Graph Title: Intersection between separate types with getter and setter does not allow assignment to property · Issue #45122 · microsoft/TypeScript

X Title: Intersection between separate types with getter and setter does not allow assignment to property · Issue #45122 · microsoft/TypeScript

Description: Bug Report I'm trying to define a property that is writable in some cases and readonly in others, by defining its getter and setter in different types and using the intersection between those when the property should be writable. However...

Open Graph Description: Bug Report I'm trying to define a property that is writable in some cases and readonly in others, by defining its getter and setter in different types and using the intersection between those when ...

X Description: Bug Report I'm trying to define a property that is writable in some cases and readonly in others, by defining its getter and setter in different types and using the intersection between those w...

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

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Intersection between separate types with getter and setter does not allow assignment to property","articleBody":"# Bug Report\r\n\r\nI'm trying to define a property that is writable in some cases and readonly in others, by defining its getter and setter in different types and using the intersection between those when the property should be writable. However, TypeScript still complains about the property not being writable.\r\n\r\n### 🔎 Search Terms\r\n\r\nintersection getter setter readonly\r\n\r\n### 🕗 Version & Regression Information\r\n\r\nReproducible on the playground with both the latest stable (4.3.5) as well as with 4.4.0 beta and the 'nightly' option.\r\n\r\n- This is the behavior in every version I tried, and I reviewed the FAQ for entries about getter / setter / readonly / intersection types\r\n\r\n### ⏯ Playground Link\r\n\r\n[Playground link with relevant code](https://www.typescriptlang.org/play?ts=4.3.5#code/C4TwDgpgBAKlC8UDeBzCwpgE4HswAoBKALigGdgsBLAOxQG4BfKAMmTPU1wIDdSLqdQo3oAoAGYBXGgGNgVHDSgBDVfmWkYhZKKgqAdNjwIoAclXLTYxkA)\r\n\r\n[Alternative attempt using `readonly`](https://www.typescriptlang.org/play?ts=4.3.5#code/C4TwDgpgBAKlC8UDeAnCBDAJgewHYBsQowVswAuKAZ2BQEtcBzAbgF8oAyZNLPQ40hWq0GjVswBQAMwCuuAMbA6eKOjUAKdJRgBKZBKiqAdCTIIoAcjXoLk1kA)\r\n\r\n### 💻 Code\r\n\r\nI've tried the following approaches - using a getter and setter:\r\n\r\n```ts\r\ntype T = {get prop(): string;} & {set prop(v: string)};\r\nfunction aaa(a: T) {\r\n  a.prop = 'aaa';\r\n}\r\n```\r\n\r\nand also using the `readonly` keyword:\r\n\r\n```ts\r\ntype T = {readonly prop: string;} & {prop: string};\r\nfunction aaa(a: T) {\r\n  a.prop = 'aaa';\r\n}\r\n```\r\n\r\n### 🙁 Actual behavior\r\n\r\nIn both cases the assignment is not allowed by the compiler, and I got a `Cannot assign to 'prop' because it is a read-only property.` error.\r\n\r\n### 🙂 Expected behavior\r\n\r\nI expected `A & B` to behave as \"This type implements both A and B at the same time\". Because of that I would have expected a readonly property defined in A to be writable if B provides a setter.\r\n","author":{"url":"https://github.com/bwrrp","@type":"Person","name":"bwrrp"},"datePublished":"2021-07-20T09:50:59Z","url":"https://github.com/microsoft/TypeScript/issues/45122"}

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:1975ab2f-8462-10e8-ee30-1a6fd0633236
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id91B6:291B58:20FFD35:29DA19F:6B01AEA4
html-safe-nonce07f109d724e18f75d1949c37f91f4bb64e0ccb64d76658f4f8bdb4d3193e4665
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5MUI2OjI5MUI1ODoyMEZGRDM1OjI5REExOUY6NkIwMUFFQTQiLCJ2aXNpdG9yX2lkIjoiMzg5MjM0MjgwNDE3NjgwOTYzNiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmacf5fae3ca9383ff7c428214085654deb7b173d06e9b23da007ac669434cc682b7
hovercard-subject-tagissue:948488469
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/45122/issue_layout
twitter:imagehttps://opengraph.githubassets.com/e5e2d4ed24a2447b596f5f699e24d8ebd99dff5c18c60d25ca5afea1235cea7e/microsoft/TypeScript/issues/45122
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/e5e2d4ed24a2447b596f5f699e24d8ebd99dff5c18c60d25ca5afea1235cea7e/microsoft/TypeScript/issues/45122
og:image:altBug Report I'm trying to define a property that is writable in some cases and readonly in others, by defining its getter and setter in different types and using the intersection between those when ...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamebwrrp
hostnamegithub.com
expected-hostnamegithub.com
Nonecc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c
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
release8c77c9e8439031ad54c75a250694842892f693e1
ui-targetcanary-2
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/microsoft/TypeScript/issues/45122#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmicrosoft%2FTypeScript%2Fissues%2F45122
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%2F45122
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/45122
Reloadhttps://github.com/microsoft/TypeScript/issues/45122
Reloadhttps://github.com/microsoft/TypeScript/issues/45122
microsofthttps://github.com/microsoft
TypeScripthttps://github.com/microsoft/TypeScript
Codehttps://github.com/microsoft/TypeScript
Issues5k (5k)https://github.com/microsoft/TypeScript/issues
Pull requests312 (312)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/insights
https://github.com/microsoft/TypeScript
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/45122
New issuehttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/45122
#45263https://github.com/microsoft/TypeScript/pull/45263
Intersection between separate types with getter and setter does not allow assignment to propertyhttps://github.com/microsoft/TypeScript/issues/45122#top
#45263https://github.com/microsoft/TypeScript/pull/45263
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
Backloghttps://github.com/microsoft/TypeScript/milestone/29
https://github.com/bwrrp
Stef Busking (bwrrp)https://github.com/bwrrp
on Jul 20, 2021https://github.com/microsoft/TypeScript/issues/45122#issue-948488469
Playground link with relevant codehttps://www.typescriptlang.org/play?ts=4.3.5#code/C4TwDgpgBAKlC8UDeBzCwpgE4HswAoBKALigGdgsBLAOxQG4BfKAMmTPU1wIDdSLqdQo3oAoAGYBXGgGNgVHDSgBDVfmWkYhZKKgqAdNjwIoAclXLTYxkA
Alternative attempt using readonlyhttps://www.typescriptlang.org/play?ts=4.3.5#code/C4TwDgpgBAKlC8UDeAnCBDAJgewHYBsQowVswAuKAZ2BQEtcBzAbgF8oAyZNLPQ40hWq0GjVswBQAMwCuuAMbA6eKOjUAKdJRgBKZBKiqAdCTIIoAcjXoLk1kA
https://github.com/jcalz
Joe Calzaretta (jcalz)https://github.com/jcalz
on Jul 21, 2021https://github.com/microsoft/TypeScript/issues/45122#issuecomment-884314253
#13347https://github.com/microsoft/TypeScript/issues/13347
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
on Jul 21, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5052794500
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
Backloghttps://github.com/microsoft/TypeScript/milestone/29
on Jul 21, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5052794578
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
help wantedhttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22help%20wanted%22
on Jul 21, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5052794767
https://github.com/RyanCavanaugh
Ryan Cavanaugh (RyanCavanaugh)https://github.com/RyanCavanaugh
on Jul 21, 2021https://github.com/microsoft/TypeScript/issues/45122#issuecomment-884536059
Stef Busking (bwrrp)https://github.com/bwrrp
on Jul 23, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5063124488
Properties on intersections should be readonly only if all declaratio…https://github.com/bwrrp/TypeScript/commit/0d9f263d15454b8439ab8c1795e4fdadd0d5ae48
https://docs.github.com/articles/closing-issues-via-commit-messages
0d9f263https://github.com/bwrrp/TypeScript/commit/0d9f263d15454b8439ab8c1795e4fdadd0d5ae48
https://github.com/bwrrp
Stef Busking (bwrrp)https://github.com/bwrrp
on Jul 24, 2021https://github.com/microsoft/TypeScript/issues/45122#issuecomment-886070712
Stef Busking (bwrrp)https://github.com/bwrrp
on Aug 1, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5095225826
Properties on intersections should be readonly only if all declaratio…https://github.com/bwrrp/TypeScript/commit/737d038cf0703c68dddf793ca4773e008b181a17
https://docs.github.com/articles/closing-issues-via-commit-messages
737d038https://github.com/bwrrp/TypeScript/commit/737d038cf0703c68dddf793ca4773e008b181a17
Stef Busking (bwrrp)https://github.com/bwrrp
on Aug 16, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5163629771
Properties on intersections should be readonly only if all declaratio…https://github.com/bwrrp/TypeScript/commit/be7275b82a408242037e8df8825c42544ee709d3
https://docs.github.com/articles/closing-issues-via-commit-messages
be7275bhttps://github.com/bwrrp/TypeScript/commit/be7275b82a408242037e8df8825c42544ee709d3
https://github.com/sandersn
Nathan Shively-Sanders (sandersn)https://github.com/sandersn
on Aug 19, 2021https://github.com/microsoft/TypeScript/issues/45122#issuecomment-902295301
microsoft/TypeScript-DOM-lib-generator#820https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/820
microsoft/TypeScript-DOM-lib-generator#715https://github.com/microsoft/TypeScript-DOM-lib-generator/pull/715
Stef Busking (bwrrp)https://github.com/bwrrp
on Aug 22, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5191090776
Properties on intersections should be readonly only if all declaratio…https://github.com/bwrrp/TypeScript/commit/c672831a391785c4417a762b82a122f8f8b83b5f
https://docs.github.com/articles/closing-issues-via-commit-messages
c672831https://github.com/bwrrp/TypeScript/commit/c672831a391785c4417a762b82a122f8f8b83b5f
Properties on intersections should be readonly only if all declaratio…https://github.com/bwrrp/TypeScript/commit/5a9ab1d87b4acc55f9d1dedf2f3b708cd6d58861
https://docs.github.com/articles/closing-issues-via-commit-messages
5a9ab1dhttps://github.com/bwrrp/TypeScript/commit/5a9ab1d87b4acc55f9d1dedf2f3b708cd6d58861
Nathan Shively-Sanders (sandersn)https://github.com/sandersn
completedhttps://github.com/microsoft/TypeScript/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
#45263https://github.com/microsoft/TypeScript/pull/45263
on Aug 25, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5209828348
Nathan Shively-Sanders (sandersn)https://github.com/sandersn
on Aug 25, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5209828476
Properties on intersections should be readonly only if all declaratio…https://github.com/microsoft/TypeScript/commit/2a2962a9164e8638c8b7d545a0842098e7c9f8f4
https://docs.github.com/articles/closing-issues-via-commit-messages
2a2962ahttps://github.com/microsoft/TypeScript/commit/2a2962a9164e8638c8b7d545a0842098e7c9f8f4
Cassandra Choi (BobobUnicorn)https://github.com/BobobUnicorn
on Oct 24, 2021https://github.com/microsoft/TypeScript/issues/45122#event-5510039410
Properties on intersections should be readonly only if all declaratio…https://github.com/BobobUnicorn/TypeScript/commit/164ec9a62537fb138d1bfea4f27d63104206525a
https://docs.github.com/articles/closing-issues-via-commit-messages
164ec9ahttps://github.com/BobobUnicorn/TypeScript/commit/164ec9a62537fb138d1bfea4f27d63104206525a
microsofthttps://github.com/microsoft
on Oct 21, 2025https://github.com/microsoft/TypeScript/issues/45122#event-20417428167
Sign up for freehttps://github.com/signup?return_to=https://github.com/microsoft/TypeScript/issues/45122
Sign in to commenthttps://github.com/login?return_to=https://github.com/microsoft/TypeScript/issues/45122
BugA bug in TypeScripthttps://github.com/microsoft/TypeScript/issues?q=state%3Aopen%20label%3A%22Bug%22
BacklogNo due datehttps://github.com/microsoft/TypeScript/milestone/29
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.