Currently, the renderer function returned by chordRendererFactory is always of the type (chord: Chord) => string.
However, if printer: "raw" is given as an option to the factory, the returned function actually returns a Chord.
Function overloads work for fixing it, by discriminating on the type of the options object.
Example:
type PrinterRaw = { printer: "raw" }
// The order is important: the first matching overload is used, hence the more specific one has to come first.
declare function chordRendererFactory(configuration: RendererConfiguration & PrinterRaw): (chord: CSChord) => CSChord
declare function chordRendererFactory(configuration?: RendererConfiguration): (chord: CSChord) => string
By the source code, I believe this issue exists with JSDoc-supplied types as well.
Currently, the renderer function returned by
chordRendererFactory
is always of the type(chord: Chord) => string
. However, ifprinter: "raw"
is given as an option to the factory, the returned function actually returns aChord
.Function overloads work for fixing it, by discriminating on the type of the options object. Example:
By the source code, I believe this issue exists with JSDoc-supplied types as well.