microsoft / microsoft/TypeScript

Enables `implements` on abstract classes with protected members (usefull for generic mixins)

Abierto
#61,161 1 comentario 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Awaiting More Feedback Suggestion
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

### 🔍 Search Terms

implement abstract class with protected

### ✅ Viability Checklist

- [x] This wouldn't be a breaking change in existing TypeScript/JavaScript code
- [x] This wouldn't change the runtime behavior of existing JavaScript code
- [x] This could be implemented without emitting different JS based on the types of the expressions
- [x] This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
- [x] This isn't a request to add a new utility type: https://github.com/microsoft/TypeScript/wiki/No-New-Utility-Types
- [x] This feature would agree with the rest of our Design Goals: https://github.com/Microsoft/TypeScript/wiki/TypeScript-Design-Goals

### ⭐ Suggestion

Enable doing the following (currently this raises an error):

```ts
abstract class Base {
protected abstract foo(): void
}

class B implements Base {
protected foo() {}
}
```

### 📃 Motivating Example

This would be useful to declare "protected" interfaces, when we can't use `extends` as the child class is already extending another.

```ts
// interface
abstract class Base {
protected abstract foo(): void
}

class C {}

class B extends C implements Base {
protected foo() {}
}
```

Such need is frequent when using generic mixins: indeed, type manipulations inside generic functions (and mixins) are often quite troublesome, with unwanted type expansions/generalization (?). Then this is often better explicitly describe the returning type.

To do so, `abstract class` is the only way to properly describe the properties added by the mixin. However, if such class has protected properties, this raises TS error as classes with protected properties are no longer duck typing but "nominal" (?).

```ts
type Cstr = new(...args:any[]) => T;
type Mergeany,
B extends new(...args:any[])=>any
> = Omit
& (new() => (InstanceType & InstanceType))

function foo>(klass: T): Merge {
return class B extends klass implements Base {
protected foo() {}
}
}

class X extends foo(C) {}
```

### 💻 Use Cases

1. What do you want to use this for?

Easily describing generic mixins return type.

2. What shortcomings exist with current approaches?

Can't describe protected properties.

3. What workarounds are you using in the meantime?

Dirty casting, removing some type checks inside the generic mixin.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

El issue no proporciona ninguna ruta de archivo ni de prueba. Empieza localizando la lógica de comprobación de tipos y las pruebas de compatibilidad de clases con `implements` con miembros protegidos, y después compara los ejemplos de clases abstractas y mixins genéricos. Se considera terminado cuando los ejemplos pasan la comprobación de tipos sin cambiar el JavaScript generado y existe cobertura de regresión.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bien especificado
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.