1/* 2* Copyright (c) 2024 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 low 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 16import collections from './@arkts.collections'; 17 18let array1: collections.Array<number> = new collections.Array<number>(); 19let set1: collections.Set<number> = new collections.Set<number>(); 20let map1: collections.Map<number, number> = new collections.Map<number, number>(); 21 22console.log(array1[0]); // Legal 23const num = 123; 24console.log(array1[num]); // Legal 25 26console.log(array1['str']); // Illegal 27const str = 'abc'; 28console.log(array1[str]); // Illegal 29 30console.log(set1[0]); // Illegal 31 32console.log(map1[0]); //Illegal 33 34let int8arr: collections.Int8Array = new collections.Int8Array(10); 35let uint8arr: collections.Uint8Array = new collections.Uint8Array(10); 36let uint8clampedarr: collections.Uint8ClampedArray = new collections.Uint8ClampedArray(10); 37let int16arr: collections.Int16Array = new collections.Int16Array(10); 38let uint16arr: collections.Uint16Array = new collections.Uint16Array(10); 39let int32arr: collections.Int32Array = new collections.Int32Array(10); 40let uint32arr: collections.Uint32Array = new collections.Uint32Array(10); 41let bitVector: collections.BitVector = new collection.BitVector(10); 42 43console.log(int8arr[0]); // Legal 44console.log(uint8arr[0]); // Legal 45console.log(uint8clampedarr[0]); // legal 46console.log(int16arr[0]); // Legal 47console.log(uint16arr[0]); // Legal 48console.log(int32arr[0]); // Legal 49console.log(uint32arr[0]); // Legal 50console.log(bitVector[0]); // Legal 51console.log(int8arr[num]); // Legal 52console.log(uint8arr[num]); // Legal 53console.log(uint8clampedarr[num]); // legal 54console.log(int16arr[num]); // Legal 55console.log(uint16arr[num]); // Legal 56console.log(int32arr[num]); // Legal 57console.log(uint32arr[num]); // Legal 58console.log(bitVector[num]); // Legal 59 60console.log(int8arr['str']); // Illegal 61console.log(uint8arr['str']); // Illegal 62console.log(uint8clampedarr['str']); // Illegal 63console.log(int16arr['str']); // Illegal 64console.log(uint16arr['str']); // Illegal 65console.log(int32arr['str']); // Illegal 66console.log(uint32arr['str']); // Illegal 67console.log(bitVector['str']); // Illegal 68console.log(int8arr[str]); // Illegal 69console.log(uint8arr[str]); // Illegal 70console.log(uint8clampedarr[str]); // Illegal 71console.log(int16arr[str]); // Illegal 72console.log(uint16arr[str]); // Illegal 73console.log(int32arr[str]); // Illegal 74console.log(uint32arr[str]); // Illegal 75console.log(bitVector['str']); // Illegal 76