Skip to content

Commit

Permalink
fix: use derived types to avoid duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisguttandin committed Dec 1, 2024
1 parent c74d685 commit 0197e68
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/factories/native-audio-worklet-node-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const createNativeAudioWorkletNodeFactory: TNativeAudioWorkletNodeFactory
});

nativeAudioWorkletNode.addEventListener = ((addEventListener) => {
return (...args: [string, EventListenerOrEventListenerObject, (boolean | AddEventListenerOptions)?]): void => {
return (...args: Parameters<TNativeAudioWorkletNode['addEventListener']>) => {
if (args[0] === 'processorerror') {
const unpatchedEventListener =
typeof args[1] === 'function'
Expand All @@ -51,9 +51,9 @@ export const createNativeAudioWorkletNodeFactory: TNativeAudioWorkletNodeFactory
const patchedEventListener = patchedEventListeners.get(args[1]);

if (patchedEventListener !== undefined) {
args[1] = patchedEventListener;
args[1] = <typeof unpatchedEventListener>patchedEventListener;
} else {
args[1] = (event: Event) => {
args[1] = (event: Parameters<typeof unpatchedEventListener>[0]) => {
// Bug #178: Chrome dispatches an event of type error.
if (event instanceof ErrorEvent && event.error === null) {
Object.defineProperties(event, {
Expand Down Expand Up @@ -83,14 +83,14 @@ export const createNativeAudioWorkletNodeFactory: TNativeAudioWorkletNodeFactory
})(nativeAudioWorkletNode.addEventListener);

nativeAudioWorkletNode.removeEventListener = ((removeEventListener) => {
return (...args: any[]): void => {
return (...args: Parameters<TNativeAudioWorkletNode['removeEventListener']>) => {
if (args[0] === 'processorerror') {
const patchedEventListener = patchedEventListeners.get(args[1]);

if (patchedEventListener !== undefined) {
patchedEventListeners.delete(args[1]);

args[1] = patchedEventListener;
args[1] = <(typeof args)[1]>patchedEventListener;
}
}

Expand Down

0 comments on commit 0197e68

Please sign in to comment.