From 141a47c8c75d94e6d1c220177833c64f0f4ec041 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=9C=E5=BA=86=E6=B3=89?= Date: Wed, 2 Nov 2022 18:09:34 +0800 Subject: [PATCH] Update uts-for-android.md --- docs/plugin/uts-for-android.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/docs/plugin/uts-for-android.md b/docs/plugin/uts-for-android.md index 68932d2ee..ed5b89cd7 100644 --- a/docs/plugin/uts-for-android.md +++ b/docs/plugin/uts-for-android.md @@ -413,6 +413,32 @@ let myListener = new MyListener(); user.setListener(myListener); ``` +#### 4.1.8 可为空函数调用 + + +有一种特殊场景,我们需要定义一些可为空的函数变量,比如下面的 success,fail: + +```ts +type Option = { + success?: (res: object) => void; + fail?: (res: object) => void; +}; + +``` + + +这个时候我们需要这样调用 + +```ts +options.success?.(res) +``` + +这样的调用方式在kotlin中是非法的,属于TS中的特有语法,需要特别注意。 + + + + + --------------------------------- ### 4.2 警告优化 -- GitLab