Skip to content

AudioWorkletProcessor can't be constructed like in the examples #1295

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

Closed
duckdoom4 opened this issue Mar 22, 2022 · 3 comments · Fixed by #1296
Closed

AudioWorkletProcessor can't be constructed like in the examples #1295

duckdoom4 opened this issue Mar 22, 2022 · 3 comments · Fixed by #1296

Comments

@duckdoom4
Copy link

See https://developer.mozilla.org/en-US/docs/Web/API/AudioWorkletProcessor/AudioWorkletProcessor

When I copy the example code I get the following error:

Argument of type 'typeof TestProcessor' is not assignable to parameter of type 'AudioWorkletProcessorConstructor'.  Type 'typeof TestProcessor' provides no match for the signature '(options: any): AudioWorkletProcessor'.

Example provided:

// test-processor.js
class TestProcessor extends AudioWorkletProcessor {
  constructor (options) {
    super()
    console.log(options.numberOfInputs)
    console.log(options.processorOptions.someUsefulVariable)
  }
  process (inputs, outputs, parameters) {
    return true
  }
}

registerProcessor('test-processor', TestProcessor)
@mathe42
Copy link
Contributor

mathe42 commented Mar 22, 2022

I would guess the problem is here:

https://github.com/microsoft/TypeScript-DOM-lib-generator/blob/main/baselines/audioworklet.generated.d.ts#L892-L894

interface AudioWorkletProcessorConstructor {
    (options: any): AudioWorkletProcessor;
}

Means the types expect something like (opt) => new TestProcessor(opt) but that is wrong it should be

interface AudioWorkletProcessorConstructor {
    new (options: any): AudioWorkletProcessor;
}

Can you try that change if that fixes it (by changing it manualy in e.g. node_modules)?

@duckdoom4
Copy link
Author

I made the modifications and now it does work correctly. I guess I can temporarily place the file in a local types folder until an update is pushed.

@mathe42
Copy link
Contributor

mathe42 commented Mar 22, 2022

I will create a PR.

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.

2 participants