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 16class A { 17 a1 : string = "" 18 a2 : number = 0 19} 20 21 22function main() { 23 let r1 = new Array<A>() 24 r1.push({a1:"A", a2: 1}, {a1:"B", a2: 2}); 25 assertEQ(r1[0].a1, "A") 26 assertEQ(r1[0].a2, 1) 27 assertEQ(r1[1].a1, "B") 28 assertEQ(r1[1].a2, 2) 29 30 let r2 = new Array<Record<string, number>>(); 31 r2.push({"A": 1}, {"B": 2}) 32 let v = r2.pop() 33 assertEQ(v!["B"], 2) 34 v = r2.pop() 35 assertEQ(v!["A"], 1) 36 37 let r3: [Record<number, string>, Record<string, (p:number) => string>] = [{1:"1", 2:"2", 3:"3"}, 38 {"A":(p:number):string=>"A" + p, "B":(p:number):string => "b" + p}] 39 assertEQ(r3[0][1], "1") 40 assertEQ(r3[0][2], "2") 41 assertEQ(r3[0][3], "3") 42 assertEQ(r3[1]["A"]!(123), "A123") 43 assertEQ(r3[1]["B"]!(123), "b123") 44}