/* * Copyright (c) 2022-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ { function rOnlyNum(num: readonly number[], num1: number[]): number { let arr: number[] = num as number[] let b = num[0] let c = num1[0] return arr[0] } let arr: number[] = [1,2,3] let arrNum = rOnlyNum(arr, arr) let s: number[] = [1,2,3] for (let c of s) { console.log(s) } } { function rOnlyNum(num: readonly ArrayLike, num1: ArrayLike): number { let arr: ArrayLike = num as ArrayLike let b = num[0] let c = num1[0] return arr[0] } let arr: ArrayLike = [1,2,3] let arrNum = rOnlyNum(arr, arr) let s: ArrayLike = [1,2,3] for (let c of s) { console.log(s) } } { function rOnlyNum(num: readonly ConcatArray, num1: ConcatArray): number { let arr: ConcatArray = num as ConcatArray let b = num[0] let c = num1[0] return arr[0] } let arr: ConcatArray = [1,2,3] let arrNum = rOnlyNum(arr, arr) let s: ConcatArray = [1,2,3] for (let c of s) { console.log(s) } } { function rOnlyNum(num: readonly ReadonlyArray, num1: ReadonlyArray): number { let arr: ReadonlyArray = num as ReadonlyArray let b = num[0] let c = num1[0] return arr[0] } let arr: ReadonlyArray = [1,2,3] let arrNum = rOnlyNum(arr, arr) let s: ReadonlyArray = [1,2,3] for (let c of s) { console.log(s) } } { function rOnlyNum(num: readonly Array, num1: Array): number { let arr: Array = num as Array let b = num[0] let c = num1[0] return arr[0] } let arr: Array = [1,2,3] let arrNum = rOnlyNum(arr, arr) let s: Array = [1,2,3] for (let c of s) { console.log(s) } }