From e4f00df887c59172c46c6c959389d1eba433aa67 Mon Sep 17 00:00:00 2001 From: hzzhouzebin Date: Tue, 30 Apr 2024 00:54:37 +0800 Subject: [PATCH 1/3] Support concat for Array Issue: https://gitee.com/openharmony/interface_sdk-js/issues/I9KT1B Signed-off-by: hzzhouzebin Change-Id: Id949f6de501a77bcd3490b2852cb5e9f0bc4f3a3 --- arkts/@arkts.collections.d.ets | 97 +++++++++++++++++++++++++++++++++- 1 file changed, 95 insertions(+), 2 deletions(-) diff --git a/arkts/@arkts.collections.d.ets b/arkts/@arkts.collections.d.ets index a686964a6..bc02b9d52 100644 --- a/arkts/@arkts.collections.d.ets +++ b/arkts/@arkts.collections.d.ets @@ -18,6 +18,8 @@ * @kit ArkTS */ +import lang from './@arkts.lang' + /** * ArkTS collections. * @@ -95,19 +97,97 @@ declare namespace collections { * @since 12 */ type TypedArrayCompareFn = (first: ElementType, second: ElementType) => number; + /** + * Redefines ISendable for convenience. + * + * @typedef { lang.ISendable } ISendable + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 12 + */ + type ISendable = lang.ISendable; + /** + * Represents an array-like object that can be concatenated. + * + * @interface ConcatArray + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 12 + */ + interface ConcatArray extends ISendable { + /** + * Gets the length of the ArkTS ConcatArray. This is a number one higher than the highest index in the ArkTS array. + * + * @type { number } + * @readonly + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 12 + */ + readonly length: number; + /** + * 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 >= array.length. + * @returns { T } The element in the ConcatArray matching the given index. + * @readonly + * @throws { BusinessError } 401 - Parameter error. Illegal index. + * @throws { BusinessError } 10200001 - The value of index is out of range. + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 12 + */ + readonly [index: number]: T; + /** + * Adds all the elements of an ArkTS ConcatArray into a string, separated by the specified separator string. + * + * @param { string } [separator] - A string used to separate one element of the array from + * the next in the resulting string. If omitted, the array elements are separated with a comma. + * @returns { string } A string with all array elements joined. + * If ConcatArray.length is 0, the empty string is returned. + * @throws { BusinessError } 401 - Parameter error. Invalid separator. + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 12 + */ + join(separator?: string): string; + /** + * Returns a copy of a section of an ArkTS ConcatArray. + * + * @param { number } [start] - The beginning index of the specified portion of the array. + * If start is undefined, then the slice begins at index 0. + * @param { number } [end] - The end index of the specified portion of the array. + * This is exclusive of the element at the index 'end'. + * If end is undefined, then the slice extends to the end of the array. + * @returns { ConcatArray } A new ConcatArray containing the extracted elements. + * @throws { BusinessError } 401 - Parameter error. Invalid `start` or `end` parameters. + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 12 + */ + slice(start?: number, end?: number): ConcatArray; + } /** * Array is a data structure that is implemented based on array. * If multiple threads access a Array instance concurrently, * and at least one of the threads modifies the array structurally, * it must be synchronized externally. * + * @implements ConcatArray * @syscap SystemCapability.Utils.Lang * @crossplatform * @atomicservice * @since 12 */ @Sendable - class Array { + class Array implements ConcatArray{ /** * Gets the length of the ArkTS array. This is a number one higher than the highest index in the ArkTS array. * @@ -123,7 +203,6 @@ declare namespace collections { * Creates an ArkTS Array with arrayLength elements initialized to initialValue. * * @param { number } arrayLength - The length of the array. - * @returns { Array } A new Array instance * @param { T } initialValue - Element initial value that will be filled into the Array. * @returns { Array } A new Array instance * @throws { BusinessError } 401 - Parameter error. @@ -548,6 +627,20 @@ declare namespace collections { * @since 12 */ [index: number]: T; + /** + * Concatenates two or more arrays. + * + * @param { ConcatArray[] } items - The arrays to concatenate. + * @returns { Array } A new array containing the elements of the concatenated arrays. + * @throws { BusinessError } 401 - Parameter error. Not a valid array. + * @throws { BusinessError } 10200011 - The concat method cannot be bound. + * @throws { BusinessError } 10200201 - Concurrent modification error. + * @syscap SystemCapability.Utils.Lang + * @crossplatform + * @atomicservice + * @since 12 + */ + concat(...items: ConcatArray[]): Array; } /** -- Gitee From 232b064e7e5ee1a1e9bd852132f1cea00554d207 Mon Sep 17 00:00:00 2001 From: hzzhouzebin Date: Tue, 14 May 2024 23:12:58 +0800 Subject: [PATCH 2/3] Remove index signature temporarily Issue: https://gitee.com/openharmony/interface_sdk-js/issues/I9KT1B Signed-off-by: hzzhouzebin Change-Id: If2aa0228cc5ca5050a20a552dabc65ebe62dbe02 --- arkts/@arkts.collections.d.ets | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/arkts/@arkts.collections.d.ets b/arkts/@arkts.collections.d.ets index bc02b9d52..84dd46f03 100644 --- a/arkts/@arkts.collections.d.ets +++ b/arkts/@arkts.collections.d.ets @@ -128,21 +128,6 @@ declare namespace collections { * @since 12 */ readonly length: number; - /** - * 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 >= array.length. - * @returns { T } The element in the ConcatArray matching the given index. - * @readonly - * @throws { BusinessError } 401 - Parameter error. Illegal index. - * @throws { BusinessError } 10200001 - The value of index is out of range. - * @syscap SystemCapability.Utils.Lang - * @crossplatform - * @atomicservice - * @since 12 - */ - readonly [index: number]: T; /** * Adds all the elements of an ArkTS ConcatArray into a string, separated by the specified separator string. * -- Gitee From 2d15490907e35f65511736e74b368d465af3d3dd Mon Sep 17 00:00:00 2001 From: hzzhouzebin Date: Fri, 17 May 2024 16:11:56 +0800 Subject: [PATCH 3/3] fix JSDoc Issue: https://gitee.com/openharmony/interface_sdk-js/issues/I9KT1B Signed-off-by: hzzhouzebin Change-Id: Ic1f43158c21a169091d2a62de2113e857ce69a18 --- arkts/@arkts.collections.d.ets | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arkts/@arkts.collections.d.ets b/arkts/@arkts.collections.d.ets index 84dd46f03..09bd4578b 100644 --- a/arkts/@arkts.collections.d.ets +++ b/arkts/@arkts.collections.d.ets @@ -118,7 +118,7 @@ declare namespace collections { */ interface ConcatArray extends ISendable { /** - * Gets the length of the ArkTS ConcatArray. This is a number one higher than the highest index in the ArkTS array. + * Gets the length of the ArkTS ConcatArray. This is a number one higher than the highest index in the array. * * @type { number } * @readonly @@ -160,7 +160,7 @@ declare namespace collections { slice(start?: number, end?: number): ConcatArray; } /** - * Array is a data structure that is implemented based on array. + * Array is a data structure that stores a collection of elements. * If multiple threads access a Array instance concurrently, * and at least one of the threads modifies the array structurally, * it must be synchronized externally. @@ -172,7 +172,7 @@ declare namespace collections { * @since 12 */ @Sendable - class Array implements ConcatArray{ + class Array implements ConcatArray { /** * Gets the length of the ArkTS array. This is a number one higher than the highest index in the ArkTS array. * -- Gitee