microsoft / microsoft/TypeScript
Inconsistent enum literal types
- Lenguaje dominante
- Go
- Estrellas
- 111k
- Forks
- 14.3k
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 132
Descripción
### 🔎 Search Terms
return type inference enum union literal fresh regular
### 🕗 Version & Regression Information
- This is the behavior in every version I tried
### ⏯ Playground Link
https://www.typescriptlang.org/play/?ts=5.8.0-dev.20250216#code/KYOwrgtgBAolDeUCCAaKAhKBfAUDgLgJ4AOwGA9gB4A8AKgHxQC8COUUA5sPgFxQAUASmaNaAbjZQAztz78AbgEMANmGB9awpo3nkAlgBMJWCTgPAAxssUAnMgDMwIC-j3kQUAEZU69BSrUNQT50HwZTC3cpfC8QAEZmLyp+AAZBMSgAekyKGnAIT2AbehxIkGjYgCYQn3zC4sTvSlT0rJyAeQBrPDKKwoSWJv4YADokVuzc6hgS3pjC6qmZxuTR8YzJmBsbchs0JumxxhByGMUpKT0OEEVPZTJ8ciWSoA
### 💻 Code
```ts
enum E { A, B }
type Box = {
get: () => T;
set: (value: T) => void;
};
declare function box(value: T): Box;
const bn1 = box(0); // Box
const bn2: Box = box(0); // Ok
const be1 = box(E.A); // Box
const be2: Box = box(E.A); // Error, box not assignable to Box
```
### 🙁 Actual behavior
`be2` errors
### 🙂 Expected behavior
`be2` shouldn't error
### Additional information about the issue
This is an enum-based variant of https://github.com/microsoft/TypeScript/issues/48363 . As such it relates to the open https://github.com/microsoft/TypeScript/issues/59754 too
Guía de contribución
Línea de trabajo
Comienza con la reproducción vinculada de TypeScript Playground y compara los tipos inferidos de bn1, bn2, be1 y be2. Lee las issues relacionadas #48363 y #59754 para conocer el contexto existente; se considera terminado cuando la asignación de be2 basada en enum ya no produce errores y se conserva el comportamiento de inferencia esperado.
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
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100