π Search Terms
Related issues:
π Version & Regression Information
- This is the behavior in every version I tried
β― Playground Link
Playground Link
π» Code
interface A { readonly foo: number; }
interface B { foo: number; }
interface C extends A, B {}
π Actual behavior
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:
Not to:
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:
With:
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.