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
|
//// [numericEnumMappedType.ts]
// Repro from #31771
enum E1 { ONE, TWO, THREE }
declare enum E2 { ONE, TWO, THREE }
type Bins1 = { [k in E1]?: string; }
type Bins2 = { [k in E2]?: string; }
const b1: Bins1 = {};
const b2: Bins2 = {};
const e1: E1 = E1.ONE;
const e2: E2 = E2.ONE;
b1[1] = "a";
b1[e1] = "b";
b2[1] = "a";
b2[e2] = "b";
// Multiple numeric enum types accrue to the same numeric index signature in a mapped type
declare function val(): number;
enum N1 { A = val(), B = val() }
enum N2 { C = val(), D = val() }
type T1 = { [K in N1 | N2]: K };
// 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' }
const e: E = E.ONE;
const x: E.ONE = e;
//// [numericEnumMappedType.js]
"use strict";
// Repro from #31771
var E1;
(function (E1) {
E1[E1["ONE"] = 0] = "ONE";
E1[E1["TWO"] = 1] = "TWO";
E1[E1["THREE"] = 2] = "THREE";
})(E1 || (E1 = {}));
var b1 = {};
var b2 = {};
var e1 = E1.ONE;
var e2 = E2.ONE;
b1[1] = "a";
b1[e1] = "b";
b2[1] = "a";
b2[e2] = "b";
var N1;
(function (N1) {
N1[N1["A"] = val()] = "A";
N1[N1["B"] = val()] = "B";
})(N1 || (N1 = {}));
var N2;
(function (N2) {
N2[N2["C"] = val()] = "C";
N2[N2["D"] = val()] = "D";
})(N2 || (N2 = {}));
var e = E.ONE;
var x = e;
//// [numericEnumMappedType.d.ts]
declare enum E1 {
ONE = 0,
TWO = 1,
THREE = 2
}
declare enum E2 {
ONE,
TWO,
THREE
}
type Bins1 = {
[k in E1]?: string;
};
type Bins2 = {
[k in E2]?: string;
};
declare const b1: Bins1;
declare const b2: Bins2;
declare const e1: E1;
declare const e2: E2;
declare function val(): number;
declare enum N1 {
A,
B
}
declare enum N2 {
C,
D
}
type T1 = {
[K in N1 | N2]: K;
};
declare enum E {
ONE = 0,
TWO = 1,
THREE = "x"
}
declare const e: E;
declare const x: E.ONE;
|