1/* 2 * Copyright (c) 2024-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 */ 15type HandlerMap = Record<int, (param: Number) => string> 16 17function main(): void { 18 let handlerMap: HandlerMap = { 19 2: (param: Number):string => { return "1" }, 20 4: (param: Number):string => { return "2" }, 21 8: (param: Number):string => { return "3" }, 22 16: (param: Number):string => { return "4" }, 23 32: (param: Number):string => { return "5" }, 24 64: (param: Number):string => { return "6" }, 25 128: (param: Number):string => { return "7" }, 26 256: (param: Number):string => { return "8" } 27 } 28 assertEQ(handlerMap.get(2)!(1), "1") 29 assertEQ(handlerMap.get(4)!(1), "2") 30 assertEQ(handlerMap.get(8)!(1), "3") 31 assertEQ(handlerMap.get(16)!(1), "4") 32 assertEQ(handlerMap.get(32)!(1), "5") 33 assertEQ(handlerMap.get(64)!(1), "6") 34 assertEQ(handlerMap.get(128)!(1), "7") 35 assertEQ(handlerMap.get(256)!(1), "8") 36} 37