microsoft / microsoft/TypeScript
Error (2320) when extending interfaces where a property is both readonly and readwrite.
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
🔎 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
💻 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:
get foo(): number;
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:
get foo(): number;
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.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza con el ejemplo enlazado de Playground y compara el comportamiento descrito en los issues relacionados 4278 y 13347. Investiga el manejo de la compatibilidad de interfaces para propiedades readonly y readwrite; se considera terminado cuando el ejemplo ya no informa del error 2320, mientras el comportamiento de compatibilidad existente sigue siendo correcto.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- typescript
- Área
- compilers
- Tipo de issue
- Error
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100