Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Intersection for same key read-only property maybe wrong #61344

Open
bysdxt opened this issue Mar 4, 2025 · 0 comments Β· May be fixed by #61346
Open

Intersection for same key read-only property maybe wrong #61344

bysdxt opened this issue Mar 4, 2025 · 0 comments Β· May be fixed by #61346
Labels
Bug A bug in TypeScript Help Wanted You can do this
Milestone

Comments

@bysdxt
Copy link

bysdxt commented Mar 4, 2025

πŸ”Ž Search Terms

Intersection readonly property

πŸ•— Version & Regression Information

  • This changed between versions 4.4.4 and 4.5.5 (But all versions have errors)

⏯ Playground Link

https://www.typescriptlang.org/play/?ts=5.4.5#code/FAFwngDgpgBAgjAvDA3jA1gLhgOwK4C2ARlAE4wC+oksAQkqjKVAIYAmA9jgDZgbb5iZSsGAAKFBRgsAzvBgAyGLQCUAOnQMADAG5xk6XPpK46zcl2jw0GAFkW6KAHVSASxAsi3KAB4AKgB8DGgAtMzsXLwwANoA0jCuOBhQYBwAZjB+ALrYfnFZlHqiVjQwAMIM9o4u7p7ePrQBehJSsuVm2s0GbRVKqhqd+q1Giu0DFkVAA

πŸ’» Code

type A = { k: number }
type B = { readonly k: number }

({} as A & B).k = 0;
({} as B & A).k = 0;

type MakeWritable<T> = { -readonly [K in keyof T]: T[K] };




type C = MakeWritable<B>;
({} as C).k = 0;
({} as C & B).k = 0;
({} as B & C).k = 0;

πŸ™ Actual behavior

command:

z:\webdl\test>tsc --target esnext --lib esnext test.ts

output:

test.ts:15:15 - error TS2540: Cannot assign to 'k' because it is a read-only property.

15 ({} as C & B).k = 0;
                 ~

test.ts:16:15 - error TS2540: Cannot assign to 'k' because it is a read-only property.

16 ({} as B & C).k = 0;
                 ~


Found 2 errors in the same file, starting at: test.ts:15

πŸ™‚ Expected behavior

no error.

Additional information about the issue

No response

@RyanCavanaugh RyanCavanaugh added Bug A bug in TypeScript Help Wanted You can do this labels Mar 4, 2025
@RyanCavanaugh RyanCavanaugh added this to the Backlog milestone Mar 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Help Wanted You can do this
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants