/* * 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. */ namespace testing { export class Array { $_get(index: number): Array {return this;} $_set(index: number, value: Array) {} } export class ReadonlyArray { $_get(index: number): ReadonlyArray {return this;} $_set(index: number, value: ReadonlyArray) {} } export class ConcatArray { $_get(index: number): ConcatArray {return this;} $_set(index: number, value: ConcatArray) {} } export class ArrayLike { $_get(index: number): ArrayLike {return this;} $_set(index: number, value: ArrayLike) {} } } namespace testing2 { export class Array {[x: number]: any} export class ReadonlyArray {[x: number]: any} export class ConcatArray {[x: number]: any} export class ArrayLike {[x: number]: any} } // no error function retA() { let a: Array = [1,2,3]; let b: ReadonlyArray = [1,2,3]; let c: ConcatArray = [1,2,3]; let d: ArrayLike = [1,2,3]; // no error return a[0] + b[0] + c[0] + d[0]; } // error function retB() { let a = new testing.Array(); let b = new testing.ReadonlyArray(); let c = new testing.ConcatArray(); let d = new testing.ArrayLike(); // no error return a[0] + b[0] + c[0] + d[0]; } // error function retC() { let a = new testing2.Array(); let b = new testing2.ReadonlyArray(); let c = new testing2.ConcatArray(); let d = new testing2.ArrayLike(); // 4 error return a[0] + b[0] + c[0] + d[0]; }