minigame-std
    Preparing search index...

    Function syncIOResultify

    • 将小游戏同步 API 转换为返回 IOResult<T> 的新函数。

      功能类似于 tryGeneralSyncOp,但以函数包装的方式使用,将可能抛出的异常捕获并转换为 IOResult

      Type Parameters

      • F extends (...args: any[]) => unknown

      Parameters

      • api: F

        小游戏同步 API。

      Returns (...args: Parameters<F>) => IOResult<ReturnType<F>>

      返回一个新的函数,该函数返回 IOResult<T>

      2.0.0

      // 将 wx.getStorageSync 转换为 IOResult 风格
      const getStorageSync = syncIOResultify(wx.getStorageSync);
      const result = getStorageSync('test');
      if (result.isOk()) {
      console.log('获取成功:', result.unwrap());
      } else {
      console.error('获取失败:', result.unwrapErr().message);
      }