microsoft / microsoft/TypeScript
Intersection for same key read-only property maybe wrong
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Go
- Sterne
- 111k
- Forks
- 14.3k
- Ø Merge
- 2 T. 4 Std.
- Gemergte PRs (30 T.)
- 132
Beschreibung
### 🔎 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
```ts
type A = { k: number }
type B = { readonly k: number }
({} as A & B).k = 0;
({} as B & A).k = 0;
type MakeWritable = { -readonly [K in keyof T]: T[K] };
type C = MakeWritable;
({} 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_
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne mit dem Playground-Link und der `test.ts`-Reproduktion und führe dann den gezeigten Befehl `tsc --target esnext --lib esnext test.ts` aus. Verfolge, wie TypeScript-Schnittmengen und readonly-Eigenschaften im Checker behandelt; die Aufgabe ist abgeschlossen, wenn die beiden `C`-Schnittmengenzuweisungen ohne TS2540 kompiliert werden, während die Reproduktion weiterhin abgedeckt bleibt.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- typescript
- Bereich
- compilers
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100