• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2025 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16enum TEST {
17  A,
18  B,
19  C
20}
21const arr = ['a', 'b', 'c'];
22
23const val = TEST[1]; //error
24const value: number = TEST.A;
25const arrVal = arr[1];
26let a = 1;
27let b = 2.3;
28let c = "str";
29let d3 = TEST[TEST.A];
30let d4 = TEST[a]; //error
31let d5 = TEST[b]; //error
32let d2 = TEST['A']; //error
33enum E { A, B, C }
34console.log(E[E.A]);
35function foo(e: E) {
36  console.log(E[e]);
37}
38foo(E.B);
39console.log(E[2 as E]);
40enum Color { Red, Green = 10, Blue }
41enum E1 { One = 1, one = 1, oNe = 1 }
42console.log(E1[1 as E1])
43let c1: Color = Color.Green;
44console.log(c1.toString())
45console.log(Color[c1]);
46enum G {
47  A = 1,
48  B = 2
49}
50console.log(G[G.A]);