File: numericEnumMappedType.types

package info (click to toggle)
node-typescript 5.0.4%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 459,140 kB
  • sloc: javascript: 1,972,754; makefile: 6; sh: 1
file content (117 lines) | stat: -rw-r--r-- 2,120 bytes parent folder | download
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
=== tests/cases/compiler/numericEnumMappedType.ts ===
// Repro from #31771

enum E1 { ONE, TWO, THREE }
>E1 : E1
>ONE : E1.ONE
>TWO : E1.TWO
>THREE : E1.THREE

declare enum E2 { ONE, TWO, THREE }
>E2 : E2
>ONE : E2.ONE
>TWO : E2.TWO
>THREE : E2.THREE

type Bins1 = { [k in E1]?: string; }
>Bins1 : { 0?: string | undefined; 1?: string | undefined; 2?: string | undefined; }

type Bins2 = { [k in E2]?: string; }
>Bins2 : { [x: number]: string | undefined; }

const b1: Bins1 = {};
>b1 : Bins1
>{} : {}

const b2: Bins2 = {};
>b2 : Bins2
>{} : {}

const e1: E1 = E1.ONE;
>e1 : E1
>E1.ONE : E1.ONE
>E1 : typeof E1
>ONE : E1.ONE

const e2: E2 = E2.ONE;
>e2 : E2
>E2.ONE : E2.ONE
>E2 : typeof E2
>ONE : E2.ONE

b1[1] = "a";
>b1[1] = "a" : "a"
>b1[1] : string | undefined
>b1 : Bins1
>1 : 1
>"a" : "a"

b1[e1] = "b";
>b1[e1] = "b" : "b"
>b1[e1] : string | undefined
>b1 : Bins1
>e1 : E1.ONE
>"b" : "b"

b2[1] = "a";
>b2[1] = "a" : "a"
>b2[1] : string | undefined
>b2 : Bins2
>1 : 1
>"a" : "a"

b2[e2] = "b";
>b2[e2] = "b" : "b"
>b2[e2] : string | undefined
>b2 : Bins2
>e2 : E2.ONE
>"b" : "b"

// Multiple numeric enum types accrue to the same numeric index signature in a mapped type

declare function val(): number;
>val : () => number

enum N1 { A = val(), B = val() }
>N1 : N1
>A : N1.A
>val() : number
>val : () => number
>B : N1.B
>val() : number
>val : () => number

enum N2 { C = val(), D = val() }
>N2 : N2
>C : N2.C
>val() : number
>val : () => number
>D : N2.D
>val() : number
>val : () => number

type T1 = { [K in N1 | N2]: K };
>T1 : { [x: number]: N1 | N2; }

// Enum types with string valued members are always literal enum types and therefore
// ONE and TWO below are not computed members but rather just numerically valued members
// with auto-incremented values.

declare enum E { ONE, TWO, THREE = 'x' }
>E : E
>ONE : E.ONE
>TWO : E.TWO
>THREE : E.THREE
>'x' : "x"

const e: E = E.ONE;
>e : E
>E.ONE : E.ONE
>E : typeof E
>ONE : E.ONE

const x: E.ONE = e;
>x : E.ONE
>E : any
>e : E.ONE