Tonejs / Tone.js

A Web Audio framework for making interactive music in the browser.
https://tonejs.github.io
MIT License
13.41k stars 976 forks source link

improvement: Allow PolySynth voice constructors to extend Monophonic #929

Closed kaylendog closed 2 years ago

kaylendog commented 3 years ago

This PR allows PolySynth to support instruments built from scratch by extending Monophonic, by inferring the Options type used by the instrument. This is safe since we know this must extend MonophonicOptions.

// in VoiceOptions<T>
/* ... */ T extends Monophonic<infer U> ? U : /* ... */

I can't forsee any issues with this conflicting with previous types above this expression, since they will match before this statement is reached - might even be simpler to use this instead of those matches!

I cannot verify whether this is passing tests - since Tone.JS appears to run its test on Node 11, it's near impossible for me to build it without resorting to Rosetta emulation - so testing would be very much appreciated! ❤️