From 6dd1f42d14cced5247a46a8a6d3838ea26d5152a Mon Sep 17 00:00:00 2001 From: zhangziye Date: Thu, 5 Jun 2025 15:13:51 +0800 Subject: [PATCH] [cherry-pick]: Modify index access method Issue: https://gitee.com/openharmony/interface_sdk-js/issues/ICM037 Signed-off-by: zhangziye --- api/@ohos.buffer.d.ts | 22 ++++++---------------- api/@ohos.util.ArrayList.d.ts | 30 +++--------------------------- api/@ohos.util.Deque.d.ts | 26 ++++++++------------------ api/@ohos.util.List.d.ts | 26 ++++++++------------------ arkts/@arkts.collections.d.ets | 20 ++++++-------------- 5 files changed, 31 insertions(+), 93 deletions(-) diff --git a/api/@ohos.buffer.d.ts b/api/@ohos.buffer.d.ts index 1627e06e8e..d3cca26d7e 100644 --- a/api/@ohos.buffer.d.ts +++ b/api/@ohos.buffer.d.ts @@ -3551,30 +3551,20 @@ declare namespace buffer { writeUIntLE(value: number, offset: number, byteLength: number): number; /** - * Returns the byte at the specified index. + * Returns the item at that index. * - * @param { number } index - byte index to read - * @returns { number | undefined } Returns the byte value at `index` + * @param { number } index - The zero-based index of the desired code unit. + * Throws error if index < 0 or index >= buffer.length. + * @returns { number } The element in the buffer matching the given index. + * @throws { BusinessError } 10200001 - The value of index is out of range. * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice * @since 20 * @arkts 1.2 */ - $_get(index: number): number | undefined; + [index: number]: number; - /** - * Sets the byte at the specified index. - * - * @param { number } index – byte index to write - * @param { number } value – byte value (0–255) - * @syscap SystemCapability.Utils.Lang - * @crossplatform - * @atomicservice - * @since 20 - * @arkts 1.2 - */ - $_set(index: number, value: number): void; } /** diff --git a/api/@ohos.util.ArrayList.d.ts b/api/@ohos.util.ArrayList.d.ts index 55f957b50b..23618e27f5 100644 --- a/api/@ohos.util.ArrayList.d.ts +++ b/api/@ohos.util.ArrayList.d.ts @@ -800,37 +800,13 @@ declare class ArrayList { * @throws { BusinessError } 401 - Parameter error. * @throws { BusinessError } 10200001 - The value of index is out of range. * @syscap SystemCapability.Utils.Lang + * @crossplatform * @atomicservice - * @since 12 + * @since arkts {'1.1':'12', '1.2':'20'} + * @arkts 1.1&1.2 */ [index: number]: T; - /** - * Returns the item at that index. - * - * @param { number } index - The zero-based index of the desired code unit. - * @returns { T } The element in the arrayList matching the given index. - * @throws { BusinessError } 10200001 - The value of index is out of range. - * @syscap SystemCapability.Utils.Lang - * @atomicservice - * @since 20 - * @arkts 1.2 - */ - $_get(index: number): T; - - /** - * Set the value of item at that index. - * - * @param { number } index - The index of the element to set. - * @param { T } value - The value to set at the specified index. - * @throws { BusinessError } 10200001 - The value of index is out of range. - * @syscap SystemCapability.Utils.Lang - * @atomicservice - * @since 20 - * @arkts 1.2 - */ - $_set(index: number, value: T): void; - /** * If the newCapacity provided by the user is greater than or equal to length, * change the capacity of the arraylist to newCapacity, otherwise the capacity will not be changed diff --git a/api/@ohos.util.Deque.d.ts b/api/@ohos.util.Deque.d.ts index 73f2f662e3..ddf7fcb85c 100644 --- a/api/@ohos.util.Deque.d.ts +++ b/api/@ohos.util.Deque.d.ts @@ -427,31 +427,21 @@ declare class Deque { * @arkts 1.2 */ forEach(callbackFn: DequeForEachCb): void; - /** - * Returns the byte at the specified index. - * - * @param { number } index - The zero-based index of the desired code unit. - * @returns { T } The element in the deque matching the given index. - * @syscap SystemCapability.Utils.Lang - * @crossplatform - * @atomicservice - * @since 20 - * @arkts 1.2 - */ - $_get(index: number): T; - /** - * Sets the byte at the specified index. - * - * @param { number } index – The index of the element to set. - * @param { T } value – The value to set at the specified index. + /** + * Returns the item at that index. + * + * @param { number } index - The zero-based index of the desired code unit. + * Throws error if index < 0 or index >= deque.length. + * @returns { T } The element in the deque matching the given index. + * @throws { BusinessError } 10200001 - The value of index is out of range. * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice * @since 20 * @arkts 1.2 */ - $_set(index: number, value: T): void; + [index: number]: T; /** * returns an iterator.Each item of the iterator is a Javascript Object diff --git a/api/@ohos.util.List.d.ts b/api/@ohos.util.List.d.ts index 405a412252..d462a06f10 100644 --- a/api/@ohos.util.List.d.ts +++ b/api/@ohos.util.List.d.ts @@ -925,32 +925,22 @@ declare class List { * @arkts 1.1&1.2 */ isEmpty(): boolean; - /** - * Returns the item at that index - * - * @param { number } index - the zero-based index of the desired code unit. - * @returns { T | undefined } the element in the list matching the given index, - * or undefined if the index is out of range. - * @syscap SystemCapability.Utils.Lang - * @crossplatform - * @atomicservice - * @since 20 - * @arkts 1.2 - */ - $_get(index: number): T | undefined; /** - * Set the value of item at that index. - * - * @param { number } index – the index of the element to set. - * @param { T } value – the value to set at the specified index + * Returns the item at that index. + * + * @param { number } index - The zero-based index of the desired code unit. + * Throws error if index < 0 or index >= list.length. + * @returns { T } The element in the list matching the given index. + * @throws { BusinessError } 10200001 - The value of index is out of range. * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice * @since 20 * @arkts 1.2 */ - $_set(index: number, value: T): void; + [index: number]: T; + /** * returns an iterator.Each item of the iterator is a Javascript Object * diff --git a/arkts/@arkts.collections.d.ets b/arkts/@arkts.collections.d.ets index f8127b775b..11b52769f0 100644 --- a/arkts/@arkts.collections.d.ets +++ b/arkts/@arkts.collections.d.ets @@ -11971,30 +11971,22 @@ declare namespace collections { * @arkts 1.2 */ values(): IterableIterator; + /** * Returns the item at that index. * * @param { number } index - The zero-based index of the desired code unit. - * @returns { number } The element in the bitVector matching the given index. + * Throws error if index < 0 or index >= bitVector.length. + * @returns { number } The element in the bitVector matching the given index. + * @throws { BusinessError } 10200001 - The value of index is out of range. * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice * @since 20 * @arkts 1.2 */ - $_get(index: number): number; - /** - * Set the value of item at that index. - * - * @param { number } index - The index of the element to set. - * @param { number } value - The value to set at the specified index. - * @syscap SystemCapability.Utils.Lang - * @atomicservice - * @crossplatform - * @since 20 - * @arkts 1.2 - */ - $_set(index: number, value: number): void; + [index: number]: number; + } /** -- Gitee