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

Taro.WebAudioContext.decodeAudioData API 函数签名错误,实现方法不明确 #17080

Open
BH4HPA opened this issue Dec 25, 2024 · 0 comments · May be fixed by #17081
Open

Taro.WebAudioContext.decodeAudioData API 函数签名错误,实现方法不明确 #17080

BH4HPA opened this issue Dec 25, 2024 · 0 comments · May be fixed by #17081

Comments

@BH4HPA
Copy link

BH4HPA commented Dec 25, 2024

相关平台

微信小程序

复现仓库

https://github.com/BH4HPA/taro-app-demo-decode-audio-data.git
小程序基础库: 3.7.2
使用框架: React

复现步骤

  1. 点击 「Test API」按钮后看控制台输出
  2. 删除 @ts-expect-error 看 TypeScript 编译器报错

期望结果

  1. 函数签名应为 微信开发者文档 中规定的
interface WebAudioContext {
    decodeAudioData(
      audioData: ArrayBuffer,
      successCallback: (buffer: AudioBuffer) => void,
      errorCallback: (error: any) => void
    ): AudioBuffer
}
  1. 方法应该直接返回 AudioBuffer 而不是一个 Promise 对象

实际结果

  1. 实际的函数签名
interface WebAudioContext {
    decodeAudioData(): AudioBuffer
}

实际的函数签名

  1. 实际返回了一个 Promise<AudioBuffer> 对象

测试代码

    const audioCtx = Taro.createWebAudioContext();
    console.log('Start decoding audio data...');
    // @ts-expect-error
    const result = audioCtx.decodeAudioData(new ArrayBuffer(0), (buffer) => {
      console.log('Decoded audio data:', buffer);
    });
    console.log('direct result:', result);
    // @ts-expect-error
    console.log('promise result:', await (result as Promise<AudioBuffer>));

测试结果

image.png

环境信息

👽 Taro v4.0.8


  Taro CLI 4.0.8 environment info:
    System:
      OS: macOS 15.1.1
      Shell: 5.9 - /bin/zsh
    Binaries:
      Node: 18.19.1 - /var/folders/d1/hzt03c6n11j9v2q90ly1f8gc0000gn/T/yarn--1735118607929-0.305493304422114/node
      Yarn: 1.22.22 - /var/folders/d1/hzt03c6n11j9v2q90ly1f8gc0000gn/T/yarn--1735118607929-0.305493304422114/yarn
      npm: 10.2.4 - ~/.nvm/versions/node/v18.19.1/bin/npm
    npmPackages:
      @tarojs/cli: 4.0.8 => 4.0.8 
      @tarojs/components: 4.0.8 => 4.0.8 
      @tarojs/helper: 4.0.8 => 4.0.8 
      @tarojs/plugin-framework-react: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-alipay: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-h5: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-harmony-hybrid: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-jd: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-qq: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-swan: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-tt: 4.0.8 => 4.0.8 
      @tarojs/plugin-platform-weapp: 4.0.8 => 4.0.8 
      @tarojs/react: 4.0.8 => 4.0.8 
      @tarojs/runtime: 4.0.8 => 4.0.8 
      @tarojs/shared: 4.0.8 => 4.0.8 
      @tarojs/taro: 4.0.8 => 4.0.8 
      @tarojs/taro-loader: 4.0.8 => 4.0.8 
      @tarojs/webpack5-runner: 4.0.8 => 4.0.8 
      babel-preset-taro: 4.0.8 => 4.0.8 
      eslint-config-taro: 4.0.8 => 4.0.8 
      react: ^18.0.0 => 18.3.1
BH4HPA added a commit to BH4HPA/taro that referenced this issue Dec 25, 2024
…at docs

Updated the `decodeAudioData` method in `WebAudioContext` to match the official WeChat Mini Program documentation:
- Modified the return type to `Promise<AudioBuffer>` instead of `AudioBuffer`, because of this method' actual response.
- Adjusted method parameters to accept `audioData`, `successCallback`, and `errorCallback`.

This fixes the TypeScript error and aligns the implementation with the expected API behavior.
Closes NervJS#17080
BH4HPA added a commit to BH4HPA/taro that referenced this issue Dec 25, 2024
…p docs

Updated the `decodeAudioData` method in `WebAudioContext` to match the official WeChat Mini Program documentation:
- Modified the return type to `Promise<AudioBuffer>` instead of `AudioBuffer`, because of this method' actual response.
- Adjusted method parameters to accept `audioData`, `successCallback`, and `errorCallback`.

This fixes the TypeScript error and aligns the implementation with the expected API behavior.
Closes NervJS#17080
This was referenced Dec 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant