Skip to content
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

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

Open
darrylnoakes opened this issue May 2, 2023 · 0 comments

Comments

@darrylnoakes
Copy link
Contributor

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.

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

No branches or pull requests

1 participant