TypeScript Version: 3.4 up to 3.6-dev20190628
Search Terms:
generic literal unknown
Code
This is expected:
functionf<T>(x: T): T{returnx;}enumE{A,B}letx=f(E.A);// x has type E, not E.AAccording to #24919 (comment) , you can get this to produce an E.A if you add an extends marker:
functionf<Textends{}|null|undefined>(x: T): T{returnx;}enumE{A,B}letx=f(E.A);// x now has type E.AExpected behavior:
I'd expect the same literal inference if you write these forms too:
functionf<Textendsunknown>(x: T): T{returnx;}functionf<Textends{}>(x: T): T{returnx;}Actual behavior:
It has the other behavior, as if you have no extends clause
Playground Link:
http://www.typescriptlang.org/play/#code/FAUwdgrgtgBAojA3jAggGhgIRgX2MAMwjAGMAXASwHswYCBGAHgBUA+ACgA8AuGZgSl7MkMAE4gyEUbU4BuXMAA2EmJ3owAvHXrs4AOhT95MAPQnVMABYBDAM4wyATwAOIePiKlKNOgCYWMCCcZOAAJvaIOAA+kIqKUcShIAQUYCChHDx8gnwi4pLSqvJ4ymSqvpp+ugZGMKbmnFZ2Di5u+igexOTUtAQAzAFBIWDhMMQA1mBUAO5gmUI5wsj5UjLFSiqcfZX91YbGZhY29k6u8DAA-BcAhEA
Related Issues:
TypeScript Version: 3.4 up to 3.6-dev20190628
Search Terms:
generic literal unknown
Code
This is expected:
According to #24919 (comment) , you can get this to produce an E.A if you add an extends marker:
Expected behavior:
I'd expect the same literal inference if you write these forms too:
Actual behavior:
It has the other behavior, as if you have no
extendsclausePlayground Link:
http://www.typescriptlang.org/play/#code/FAUwdgrgtgBAojA3jAggGhgIRgX2MAMwjAGMAXASwHswYCBGAHgBUA+ACgA8AuGZgSl7MkMAE4gyEUbU4BuXMAA2EmJ3owAvHXrs4AOhT95MAPQnVMABYBDAM4wyATwAOIePiKlKNOgCYWMCCcZOAAJvaIOAA+kIqKUcShIAQUYCChHDx8gnwi4pLSqvJ4ymSqvpp+ugZGMKbmnFZ2Di5u+igexOTUtAQAzAFBIWDhMMQA1mBUAO5gmUI5wsj5UjLFSiqcfZX91YbGZhY29k6u8DAA-BcAhEA
Related Issues: