TypeScript/tests/cases/compiler/enumLiteralUnionNotWidened.ts
Wesley Wigham f8b6a8fc8d
Introduce literal freshness for literal enum member types (#26556)
* Introduce literal freshness for literal enum members, allow enum references in ambient const initializers

* Merge statements

* Add enum literal readonly property test case

* Accept better baselines post-merge
2018-09-07 12:09:07 -07:00

20 lines
573 B
TypeScript

// repro from #22093
enum A { one = "one", two = "two" };
enum B { foo = "foo", bar = "bar" };
type C = A | B.foo;
type D = A | "foo";
class List<T>
{
private readonly items: T[] = [];
}
function asList<T>(arg: T): List<T> { return new List(); }
// TypeScript incorrectly infers the return type of "asList(x)" to be "List<A | B>"
// The correct type is "List<A | B.foo>"
function fn1(x: C): List<C> { return asList(x); }
// If we use the literal "foo" instead of B.foo, the correct type is inferred
function fn2(x: D): List<D> { return asList(x); }