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 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 */ 15function foo1(param: number | string): number | string{ 16 if(param instanceof Number){ 17 return param as number 18 } 19 return param 20} 21 22function foo2(param: number | string): number | string{ 23 if(param instanceof string){ 24 return param as string 25 } 26 return param 27} 28 29function foo3(param: number | string | int[]): number | string | int[]{ 30 if(param instanceof Number){ 31 return param as number 32 } 33 return param 34} 35 36function main(){ 37 assert foo1(1) == 1 38 assert foo1("123") == "123" 39 assert foo2(1) == 1 40 assert foo2("123") == "123" 41 assert foo3(1) == 1 42 assert foo3("123") == "123" 43 let a = foo3([1, 2, 3]) as int[] 44 assert a[0]==1 45 assert a[1]==2 46 assert a[2]==3 47}