1/* 2 * Copyright (c) 2022-2023 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 16class LiteralAsPropertyName { 17 public one: string = "1111111111"; 18 private 2: string; 19 'Two': number; 20} 21 22const litAsPropName: LiteralAsPropertyName = { 23 one: "1", 24 2: 'two', 25 'Two': 2, 26}; 27 28console.log(litAsPropName["one"]); 29console.log(litAsPropName[2]); 30console.log(litAsPropName["Two"]); 31 32class LiteralAsPropertyName_fix { 33 public one: string = "1111111111"; 34 private _2: string; 35 Two: number; 36} 37 38const litAsPropName_fix: LiteralAsPropertyName_fix = { 39 one: "1111111111", 40 _2: 'two', 41 Two: 2, 42}; 43 44console.log("Fixed listAsPropName:"); 45console.log(litAsPropName_fix.one); 46console.log(litAsPropName_fix._2); 47console.log(litAsPropName_fix.Two); 48 49let x = {"name": 20, 2: 30} 50 51console.log(x["name"]); 52console.log(x[2]); 53 54class X_class { 55 public name: number; 56 public _2: number; 57} 58 59let x_fix = {name: 20, _2: 20}; 60 61console.log("Fixed x object literal:"); 62console.log(x_fix.name); 63console.log(x_fix._2);