microsoft / microsoft/TypeScript
Inconsistent enum literal types
- Lingua principale
- Go
- Stelle
- 111k
- Fork
- 14.3k
- Merge medio
- 2g 4h
- PR unite (30g)
- 132
Descrizione
### 🔎 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
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Inizia con la riproduzione collegata in TypeScript Playground e confronta i tipi inferiti di bn1, bn2, be1 e be2. Leggi le issue correlate #48363 e #59754 per il contesto esistente; il lavoro è completato quando l’assegnazione di be2 basata su enum non genera più errori, preservando il comportamento di inferenza previsto.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- typescript
- Ambito
- compilers
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100