microsoft / microsoft/TypeScript
Inconsistent enum literal types
- Dominant language
- Go
- Stars
- 111k
- Forks
- 14.3k
- PR merge metrics
- PR metrics pending
Description
### 🔎 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
Contributor guide
Research direction
Start with the linked TypeScript Playground reproduction and compare the inferred types of bn1, bn2, be1, and be2. Read the related issues #48363 and #59754 for existing context; done means the enum-based be2 assignment no longer errors while preserving the expected inference behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100