microsoft / microsoft/TypeScript

Broken inference for generic classes passed to a generic function taking an optional class

Abierto
#61,633 4 comentarios 0 reacciones 1 asignado Ver en GitHub

@ahejlsberg ya está trabajando en esto.

Desde el 30/4/2025.

Needs Investigation
Lenguaje dominante
Go
Estrellas
111k
Forks
14.3k
Merge medio
2 d 4 h
PR fusionados (30 d)
132

Descripción

### 🔎 Search Terms

class inference, optional class, broken inference

### 🕗 Version & Regression Information

This changed in PR https://github.com/microsoft/TypeScript/pull/31116

However, this was the first time that there was even a distinction between a generic and non-generic class during inference to my knowledge. This likely means this has existed ever since the ability to infer a generic class has existed.

### ⏯ Playground Link

https://www.typescriptlang.org/play/?#code/C4TwDgpgBAggdiAwgezgZ2AJwK4GNjKZQC8UcEA7lABQB09AhpgOZoBcUDCA2gLoCUJAHxRkAIwBWEfAG4AUHIBm2OPgCWqKACUIcACYRMAMQA2DVgFk1ADzVwAPACEGaCIjNo0UCNeC69XvBIqBg4+IRQAD5QKgaKdhB6JDH6EPHkekLUclC5UM6uAPwcBW4eaAA0coIA3gC+8nK45VAocMAMCZj2ACoi9Qo6qcZmljZ21G0dXfxyAPRzeUvLeQB6sCzYALa6wKKKUKCQUADkRxDIB1Od5JgnUGpecMh7LmhqzHAMYibQBFBgJgMHZ+IiXQ7gaAnWJpBJ6E60IA

### 💻 Code

```ts
type AnyConstructor = new (...args: any[]) => object;

function RenderFlagsMixin(
Base?: BaseClass,
) {};

class Container {}
// ^ Only happens when the class is generic.

RenderFlagsMixin(Container)
// ^ Argument of type 'typeof Container' is not assignable to parameter of type 'undefined'.
```

### 🙁 Actual behavior

`BaseClass` is inferred as `undefined` despite the call being the value `Container`.

### 🙂 Expected behavior

`BaseClass` should be inferred as `typeof Container`.

### Additional information about the issue

_No response_

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.

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.