1# Types 2<!--Kit: ArkTS--> 3<!--Subsystem: CommonLibrary--> 4<!--Owner: @lijiamin2025--> 5<!--Designer: @weng-changcheng--> 6<!--Tester: @kirl75; @zsw_zhushiwei--> 7<!--Adviser: @ge-yafang--> 8> **说明:** 9> 10> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 11> 12> 此模块仅支持在ArkTS文件(文件后缀为.ets)中导入使用。 13 14## ISendable 15 16type ISendable = lang.ISendable 17 18ISendable是所有Sendable类型(除`null`和`undefined`)的父类型。自身没有任何必须的方法和属性。 19 20**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 21 22**系统能力:** SystemCapability.Utils.Lang 23 24| 类型 | 说明 | 25| ------ | ------ | 26| [lang.ISendable](js-apis-arkts-lang.md#langisendable) | 所有Sendable类型的父类型。 | 27 28## ArrayFromMapFn<sup>18+</sup> 29type ArrayFromMapFn<FromElementType, ToElementType> = (value: FromElementType, index: number) => ToElementType 30 31ArkTS Array归约函数类型,被Array类的'from' 接口使用。 32 33**系统能力:** SystemCapability.Utils.Lang 34 35**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 36 37**参数:** 38 39| 参数名 | 类型 | 必填 | 说明 | 40| ------- | ------ | ---- | --------------------------- | 41| value | FromElementType | 是 | 当前正在处理的元素。| 42| index | number | 是 | 当前遍历的ArkTS Array元素下标。 | 43 44**返回值:** 45 46| 类型 | 说明 | 47| ------ | --------------------------- | 48| ToElementType | 归约函数的结果,该结果会作为数组的新元素。 | 49 50## ArrayPredicateFn<sup>18+</sup> 51type ArrayPredicateFn<ElementType, ArrayType> = (value: ElementType, index: number, array: ArrayType) => boolean 52 53ArkTS Array归约函数类型,被Array类的'some'和'every'接口使用,用来判断数组元素是否满足测试条件。 54 55**系统能力:** SystemCapability.Utils.Lang 56 57**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 58 59**参数:** 60 61| 参数名 | 类型 | 必填 | 说明 | 62| ------- | ------ | ---- | --------------------------- | 63| value | ElementType | 是 | 当前正在处理的元素。| 64| index | number | 是 | 当前遍历的ArkTS Array元素下标。 | 65| array | ArrayType | 是 | 当前遍历的ArkTS Array本身。 | 66 67**返回值:** 68 69| 类型 | 说明 | 70| ------ | --------------------------- | 71| boolean | 归约函数的结果,该结果作为判断当前元素是否通过测试条件。为true时表示当前或之前的某个元素已满足条件,为false时表示尚未找到符合条件的元素。 | 72 73## ArrayReduceCallback<sup>18+</sup> 74type ArrayReduceCallback<AccType, ElementType, ArrayType> = 75 (previousValue: AccType, currentValue: ElementType, currentIndex: number, array: ArrayType) => AccType 76 77ArkTS Array归约函数类型,被Array类的'reduceRight'接口使用。 78 79**系统能力:** SystemCapability.Utils.Lang 80 81**原子化服务API:** 从API version 18开始,该接口支持在原子化服务中使用。 82 83**参数:** 84 85| 参数名 | 类型 | 必填 | 说明 | 86| ------- | ------ | ---- | --------------------------- | 87| previousValue | AccType | 是 | 当前遍历所累积的值。| 88| currentValue | ElementType | 是 | 当前遍历的ArkTS Array元素。 | 89| currentIndex | number | 是 | 当前遍历的ArkTS Array元素下标。 | 90| array | ArrayType | 是 | 当前遍历的ArkTS Array实例。 | 91 92**返回值:** 93 94| 类型 | 说明 | 95| ------ | --------------------------- | 96| AccType | 归约函数的结果,该结果会作为下一次调用ArrayReduceCallback时的previousValue参数。 | 97 98 99 100## TypedArrayFromMapFn 101type TypedArrayFromMapFn\<FromElementType, ToElementType> = (value: FromElementType, index: number) => ToElementType 102 103ArkTS TypedArray映射函数类型。 104 105**系统能力:** SystemCapability.Utils.Lang 106 107**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 108 109**参数:** 110 111| 参数名 | 类型 | 必填 | 说明 | 112| ------- | ------ | ---- | --------------------------- | 113| value | FromElementType | 是 | 当前遍历的用于构造ArkTS TypedArray的元素。 | 114| index | number | 是 | 当前遍历的用于构造ArkTS TypedArray的元素下标,从0开始。 | 115 116**返回值:** 117 118| 类型 | 说明 | 119| ------ | --------------------------- | 120| ToElementType | 转换后的元素值。 | 121 122## TypedArrayPredicateFn 123type TypedArrayPredicateFn\<ElementType, ArrayType> = (value: ElementType, index: number, array: ArrayType) => boolean 124 125ArkTS TypedArray断言测试函数类型。 126 127**系统能力:** SystemCapability.Utils.Lang 128 129**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 130 131**参数:** 132 133| 参数名 | 类型 | 必填 | 说明 | 134| ------- | ------ | ---- | --------------------------- | 135| value | ElementType | 是 | 当前遍历的ArkTS TypedArray元素。 | 136| index | number | 是 | 当前遍历的ArkTS TypedArray元素下标,从0开始。 | 137| array | ArrayType | 是 | 当前遍历的ArkTS TypedArray实例。 | 138 139**返回值:** 140 141| 类型 | 说明 | 142| ------ | --------------------------- | 143| boolean | 如果值符合条件,则为true,否则为false。 | 144 145## TypedArrayForEachCallback 146type TypedArrayForEachCallback\<ElementType, ArrayType> = (value: ElementType, index: number, array: ArrayType) => void 147 148ArkTS TypedArray遍历函数类型。 149 150**系统能力:** SystemCapability.Utils.Lang 151 152**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 153 154**参数:** 155 156| 参数名 | 类型 | 必填 | 说明 | 157| ------- | ------ | ---- | --------------------------- | 158| value | ElementType | 是 | 当前遍历的ArkTS TypedArray元素。 | 159| index | number | 是 | 当前遍历的ArkTS TypedArray元素下标,从0开始。 | 160| array | ArrayType | 是 | 当前遍历的ArkTS TypedArray实例。 | 161 162## TypedArrayMapCallback 163type TypedArrayMapCallback\<ElementType, ArrayType> = (value: ElementType, index: number, array: ArrayType) => ElementType 164 165ArkTS TypedArray转换映射函数类型。 166 167**系统能力:** SystemCapability.Utils.Lang 168 169**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 170 171**参数:** 172 173| 参数名 | 类型 | 必填 | 说明 | 174| ------- | ------ | ---- | --------------------------- | 175| value | ElementType | 是 | 当前映射的ArkTS TypedArray元素。 | 176| index | number | 是 | 当前映射的ArkTS TypedArray元素下标,从0开始。 | 177| array | ArrayType | 是 | 当前映射的ArkTS TypedArray实例。 | 178 179**返回值:** 180 181| 类型 | 说明 | 182| ------ | --------------------------- | 183| ElementType | 转换后的元素值。 | 184 185## TypedArrayReduceCallback 186type TypedArrayReduceCallback\<AccType, ElementType, ArrayType> = (previousValue: AccType, currentValue: ElementType, currentIndex: number, array: ArrayType) => AccType 187 188ArkTS TypedArray归约函数类型。 189 190**系统能力:** SystemCapability.Utils.Lang 191 192**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 193 194**参数:** 195 196| 参数名 | 类型 | 必填 | 说明 | 197| ------- | ------ | ---- | --------------------------- | 198| previousValue | AccType | 是 | 当前遍历所累积的值。| 199| currentValue | ElementType | 是 | 当前遍历的ArkTS TypedArray元素。 | 200| currentIndex | number | 是 | 当前遍历的ArkTS TypedArray元素下标,从0开始。 | 201| array | ArrayType | 是 | 当前遍历的ArkTS TypedArray实例。 | 202 203**返回值:** 204 205| 类型 | 说明 | 206| ------ | --------------------------- | 207| AccType | 归约函数的结果。该结果会作为下一次调用TypedArrayReduceCallback时的previousValue参数。 | 208 209## TypedArrayCompareFn 210type TypedArrayCompareFn\<ElementType> = (first: ElementType, second: ElementType) => number 211 212ArkTS TypedArray排序函数类型。 213 214**系统能力:** SystemCapability.Utils.Lang 215 216**原子化服务API:** 从API version 12开始,该接口支持在原子化服务中使用。 217 218**参数:** 219 220| 参数名 | 类型 | 必填 | 说明 | 221| ------- | ------ | ---- | --------------------------- | 222| first | ElementType | 是 | 当前待比较的第一个元素。 | 223| second | ElementType | 是 | 当前待比较的第二个元素。 | 224 225**返回值:** 226 227| 类型 | 说明 | 228| ------ | --------------------------- | 229| number | 元素比较的结果。如果`first`小于`second`,返回值为负数;如果`first`大于`second`,返回值为正数;如果两个值相等,返回值为0。 | 230