From 561116f276c5f28ac6581dcf653e344e73f7d030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E4=BA=9A=E7=90=AA?= Date: Mon, 18 Nov 2024 11:28:30 +0800 Subject: [PATCH] docs: update uts-type --- docs/uts/data-type.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/uts/data-type.md b/docs/uts/data-type.md index ce8dfd1d..8b30bf28 100644 --- a/docs/uts/data-type.md +++ b/docs/uts/data-type.md @@ -645,6 +645,22 @@ console.log(a == null) // true console.log(b == null) // false ``` +HBuilderX 4.31之前的版本,在编译为kotlin或swift时,uts不会自动推断函数的返回值,因此在函数返回值并非undefined类型时需要自行添加返回值的类型信息。例如如下代码 + +```ts +const arr: number[] = [1,2,3] + +// 错误写法 +const arr1: number[] = arr.map((item: number) => { + return item + 1;‌ +}); + +// 正确写法 +const arr2: number[] = arr.map((item: number): number => { + return item + 1;‌ +}); +``` + ## 日期(Date)@date 日期对象表示日期,包括年月日时分秒等各种日期。 -- GitLab