mirror of
https://github.com/hanzoai/tsgo.git
synced 2026-10-30 19:37:15 +00:00
51 lines
1.3 KiB
TypeScript
51 lines
1.3 KiB
TypeScript
//// [tests/cases/compiler/enumLiteralUnionNotWidened.ts] ////
|
|
|
|
//// [enumLiteralUnionNotWidened.ts]
|
|
// 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); }
|
|
|
|
//// [enumLiteralUnionNotWidened.js]
|
|
"use strict";
|
|
// repro from #22093
|
|
var A;
|
|
(function (A) {
|
|
A["one"] = "one";
|
|
A["two"] = "two";
|
|
})(A || (A = {}));
|
|
;
|
|
var B;
|
|
(function (B) {
|
|
B["foo"] = "foo";
|
|
B["bar"] = "bar";
|
|
})(B || (B = {}));
|
|
;
|
|
class List {
|
|
constructor() {
|
|
this.items = [];
|
|
}
|
|
}
|
|
function asList(arg) { 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) { return asList(x); }
|
|
// If we use the literal "foo" instead of B.foo, the correct type is inferred
|
|
function fn2(x) { return asList(x); }
|