Closed
Description
TypeScript Version: 3.4 up to 3.6-dev20190628
Search Terms:
generic literal unknown
Code
This is expected:
function f<T>(x: T): T { return x; }
enum E { A, B }
let x = f(E.A); // x has type E, not E.A
According to #24919 (comment) , you can get this to produce an E.A if you add an extends marker:
function f<T extends {}|null|undefined>(x: T): T { return x; }
enum E { A, B }
let x = f(E.A); // x now has type E.A
Expected behavior:
I'd expect the same literal inference if you write these forms too:
function f<T extends unknown>(x: T): T { return x; }
function f<T extends {}>(x: T): T { return x; }
Actual behavior:
It has the other behavior, as if you have no extends
clause
Playground Link:
Related Issues: