Closed as not planned
Description
π Search Terms
Inference, Reduce
π Version & Regression Information
- This changed between versions 5.5.4 and 5.6.0-beta (still happening in 5.6.1-rc)
β― Playground Link
π» Code
interface SomeType {
enu: SomeEnum;
}
enum SomeEnum {
A = 1,
B = 2,
C = 3,
D = 4,
}
declare const vals: SomeType[];
const smallestEnu = vals.reduce(
(minEnu, val) => Math.min(minEnu, val.enu),
SomeEnum.D,
);
smallestEnu;
// ^?
π Actual behavior
smallestEnu
has type number
π Expected behavior
smallestEnu
has type SomeEnum
as it did in previous releases
Additional information about the issue
Interestingly, this does not repro if you remove the container type:
https://www.typescriptlang.org/play/?ts=5.6.1-rc#code/KYOwrgtgBAyg9hYBRc0DeAoK2oEEoC8UAjADRY4BChUATOTlAMI0DMDOAIjQCzkC+GDABNgAYwA2AQwBOwKGLggAzgBcooSMoBcsBMlQBtALoBuIYpXrlEKRInA1KMDU0RlAOjnCwY4AAoKbH8IAEsQZ1INcABKQgA+KABZKVUACw8wkBDwyOiwGI5seERnCA9OchjzGzsHJ3BzAHomqAA9AH4MIA
(Google note: relevant source location http://shortn/_JgMRGaMa4e)