microsoft / microsoft/TypeScript

Error (2320) when extending interfaces where a property is both readonly and readwrite.

Open
#63,218 4 comments 0 reactions 0 assignees View on GitHub
Awaiting More Feedback Suggestion
Dominant language
Go
Stars
111k
Forks
14.3k
PR merge metrics
PR metrics pending

Description

### 🔎 Search Terms

Related issues:
- https://github.com/microsoft/TypeScript/issues/4278
- https://github.com/microsoft/TypeScript/issues/13347

### 🕗 Version & Regression Information

- This is the behavior in every version I tried

### ⏯ Playground Link

[Playground Link](https://www.typescriptlang.org/play/?ts=6.0.0-dev.20260224#code/JYOwLgpgTgZghgYwgAgILIN4Chm+VCOAEwHsQAbAT2RhJIC5kQBXAWwCNoBuLAXy1CRYiFACFMOPLQZM2nKD34Dw0eEmQBhZBAAekEEQDOaADTJxGXkA)

### 💻 Code

```ts
interface A { readonly foo: number; }
interface B { foo: number; }

interface C extends A, B {}
```

### 🙁 Actual behavior

```ts
Interface 'C' cannot simultaneously extend types 'A' and 'B'.
Named property 'foo' of types 'A' and 'B' are not identical.(2320)
```

### 🙂 Expected behavior

No error.

### Additional information about the issue

As far as I understand, `readonly` isn't a constraint, but an interface specification.
Meaning, that `readonly foo: number` is almost equivalent to:
```ts
get foo(): number;
```
Not to:
```ts
get foo(): number;
set foo(_: never): void; // If I'm not mistaken this should forbid assignations.
```

_(TBH, a `read` keyword would be less confusing than `readonly`.)_

Therefore, here, I want to merge:
```ts
get foo(): number;
```
With:
```ts
get foo(): number;
set foo(f: number): void;
```

We can see it as:
- "merging" 2 identical getters, which cause no issue.
- adding an additional property (like we could add a method) : the setter.

However, the latter causes an issue when it shouldn't. This is just adding something.

Note: TS requires the 2 types of `foo` to be strictly identical.
_But_, when one is `readonly`, then it could accept the second to be a specialization of it (i.e. assignable to the `readonly` version).

Indeed, the resulting interface would still be assignable to the first one.

Contributor guide

Open the contributing guide

Research direction

Start with the linked Playground example and compare the behavior described in related issues 4278 and 13347. Investigate the interface-compatibility handling for readonly and readwrite properties; done means the example no longer reports error 2320 while existing compatibility behavior remains correct.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.