File: enumLiteralUnionNotWidened.symbols

package info (click to toggle)
node-typescript 4.9.5%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 533,908 kB
  • sloc: javascript: 2,018,330; makefile: 7; sh: 1
file content (61 lines) | stat: -rw-r--r-- 2,979 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
=== tests/cases/compiler/enumLiteralUnionNotWidened.ts ===
// repro from #22093
enum A { one = "one", two = "two" };
>A : Symbol(A, Decl(enumLiteralUnionNotWidened.ts, 0, 0))
>one : Symbol(A.one, Decl(enumLiteralUnionNotWidened.ts, 1, 8))
>two : Symbol(A.two, Decl(enumLiteralUnionNotWidened.ts, 1, 21))

enum B { foo = "foo", bar = "bar" };
>B : Symbol(B, Decl(enumLiteralUnionNotWidened.ts, 1, 36))
>foo : Symbol(B.foo, Decl(enumLiteralUnionNotWidened.ts, 2, 8))
>bar : Symbol(B.bar, Decl(enumLiteralUnionNotWidened.ts, 2, 21))

type C = A | B.foo;
>C : Symbol(C, Decl(enumLiteralUnionNotWidened.ts, 2, 36))
>A : Symbol(A, Decl(enumLiteralUnionNotWidened.ts, 0, 0))
>B : Symbol(B, Decl(enumLiteralUnionNotWidened.ts, 1, 36))
>foo : Symbol(B.foo, Decl(enumLiteralUnionNotWidened.ts, 2, 8))

type D = A | "foo";
>D : Symbol(D, Decl(enumLiteralUnionNotWidened.ts, 4, 19))
>A : Symbol(A, Decl(enumLiteralUnionNotWidened.ts, 0, 0))

class List<T>
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 7, 11))
{
	private readonly items: T[] = [];
>items : Symbol(List.items, Decl(enumLiteralUnionNotWidened.ts, 8, 1))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 7, 11))
}

function asList<T>(arg: T): List<T> { return new List(); }
>asList : Symbol(asList, Decl(enumLiteralUnionNotWidened.ts, 10, 1))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 12, 16))
>arg : Symbol(arg, Decl(enumLiteralUnionNotWidened.ts, 12, 19))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 12, 16))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>T : Symbol(T, Decl(enumLiteralUnionNotWidened.ts, 12, 16))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))

// 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); }
>fn1 : Symbol(fn1, Decl(enumLiteralUnionNotWidened.ts, 12, 58))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 16, 13))
>C : Symbol(C, Decl(enumLiteralUnionNotWidened.ts, 2, 36))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>C : Symbol(C, Decl(enumLiteralUnionNotWidened.ts, 2, 36))
>asList : Symbol(asList, Decl(enumLiteralUnionNotWidened.ts, 10, 1))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 16, 13))

// If we use the literal "foo" instead of B.foo, the correct type is inferred
function fn2(x: D): List<D> { return asList(x); }
>fn2 : Symbol(fn2, Decl(enumLiteralUnionNotWidened.ts, 16, 49))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 19, 13))
>D : Symbol(D, Decl(enumLiteralUnionNotWidened.ts, 4, 19))
>List : Symbol(List, Decl(enumLiteralUnionNotWidened.ts, 5, 19))
>D : Symbol(D, Decl(enumLiteralUnionNotWidened.ts, 4, 19))
>asList : Symbol(asList, Decl(enumLiteralUnionNotWidened.ts, 10, 1))
>x : Symbol(x, Decl(enumLiteralUnionNotWidened.ts, 19, 13))