Microsoft/TypeScript
Ver no GitHubIntersection for same key read-only property maybe wrong
Open
#61.344 aberto em 4 de mar. de 2025
BugDomain: IntersectionHelp Wanted
Métricas do repositório
- Stars
- (48.455 stars)
- Métricas de merge de PR
- (Mesclagem média 6d 17h) (9 fundiu PRs em 30d)
Description
🔎 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
💻 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