Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getRandomValues返回值为undefined #13673

Closed
DZG-MELODY opened this issue Apr 15, 2023 · 1 comment
Closed

getRandomValues返回值为undefined #13673

DZG-MELODY opened this issue Apr 15, 2023 · 1 comment
Labels
A-typings Area - TypeScript Typings 相关 E-easy Helper Wanted - Easy T-weapp Target - 编译到微信小程序
Milestone

Comments

@DZG-MELODY
Copy link

DZG-MELODY commented Apr 15, 2023

相关平台

微信小程序

小程序基础库: 2.30.4
使用框架: Vue 3

复现步骤

直接调用:

const res = await Taro.getUserCryptoManager().getRandomValues({length:24})
// res 为 undefined

返回结果为undefined,但文档中描述为支持Promise调用

使用回调函数success可以获得结果,但ts类型推断缺失randomValues字段

Taro.getUserCryptoManager().getRandomValues({
length:24,
success(res){
  // ts报错 不存在randomValues
  //res.randomValues
}
})

期望结果

通过await调用可以获得结果

实际结果

获得undefined

环境信息

👽 Taro v3.6.4


  Taro CLI 3.6.4 environment info:
    System:
      OS: macOS 13.2
      Shell: 5.8.1 - /bin/zsh
    Binaries:
      Node: 19.5.0 - /usr/local/bin/node
      Yarn: 1.22.19 - /usr/local/bin/yarn
      npm: 9.3.1 - /usr/local/bin/npm
    npmPackages:
      @tarojs/cli: 3.6.4 => 3.6.4 
      @tarojs/components: 3.6.4 => 3.6.4 
      @tarojs/helper: 3.6.4 => 3.6.4 
      @tarojs/plugin-framework-vue3: 3.6.4 => 3.6.4 
      @tarojs/plugin-html: 3.6.4 => 3.6.4 
      @tarojs/plugin-platform-alipay: 3.6.4 => 3.6.4 
      @tarojs/plugin-platform-h5: 3.6.4 => 3.6.4 
      @tarojs/plugin-platform-jd: 3.6.4 => 3.6.4 
      @tarojs/plugin-platform-qq: 3.6.4 => 3.6.4 
      @tarojs/plugin-platform-swan: 3.6.4 => 3.6.4 
      @tarojs/plugin-platform-tt: 3.6.4 => 3.6.4 
      @tarojs/plugin-platform-weapp: 3.6.4 => 3.6.4 
      @tarojs/runtime: 3.6.4 => 3.6.4 
      @tarojs/shared: 3.6.4 => 3.6.4 
      @tarojs/taro: 3.6.4 => 3.6.4 
      @tarojs/taro-loader: ^3.6.4 => 3.6.4 
      @tarojs/webpack5-runner: 3.6.4 => 3.6.4 
      babel-preset-taro: 3.6.4 => 3.6.4 
      eslint-config-taro: 3.6.4 => 3.6.4 
@TheKonka TheKonka added the T-weapp Target - 编译到微信小程序 label Apr 16, 2023
@ZakaryCode ZakaryCode added A-typings Area - TypeScript Typings 相关 E-easy Helper Wanted - Easy labels Apr 17, 2023
@xuanzebin
Copy link
Member

xuanzebin commented Apr 21, 2023

Taro 因为只劫持了第一层 api 的调用,因此目前暂时无法对上述 api Taro.xxxx.getRandomValues 进行 Promise 类型的调用。
看了一下微信小程序的文档,这个 api 也支持在第一层直接调用,因此如果确实需要 Promise 类型的调用,你可以将代码修改为:

// @ts-ignore
const value = await Taro.getRandomValues({ length: 10 })

而类型报错是类型文件没有对齐小程序文档,目前存在两个类型问题:

  • getRandomValues success 回调函数返回结果类型不正确
  • 第一层调用不存在 api getRandomValues

这个会在下个版本修复,可以先通过 ts-ignore 的方式来解决报错。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typings Area - TypeScript Typings 相关 E-easy Helper Wanted - Easy T-weapp Target - 编译到微信小程序
Projects
None yet
Development

No branches or pull requests

4 participants