Skip to content

The chord renderer factory should change the type of the returned function based on the printer option #642

@darrylnoakes

Description

@darrylnoakes

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions