mpd-api icon indicating copy to clipboard operation
mpd-api copied to clipboard

wrong / unclear typing of boolean arguments

Open f-messner opened this issue 2 weeks ago • 0 comments

Hi, when an endpoint requires a boolean parameter (for example api.playback.random ) then the internal method boolAt converts any truthy value to 1 and falsy values to 0. However, due to the typing of the api, the function random only takes an arbitrary amount of strings (or MPD.Command which doesn't seem to be documented?)

So all of the following set the player to randomize:

mpdClient.api.playback.random("1")
mpdClient.api.playback.random("true")
mpdClient.api.playback.random("0")
mpdClient.api.playback.random("false")

While these are the only ways to un-randomize:

mpdClient.api.playback.random()
mpdClient.api.playback.random("")

Notably, ignoring the typing, this also works:

mpdClient.api.playback.random(false)

My suggestion would be to either loosen the typing to allow boolean values specifically in addition to strings, OR to add explicit typings for all endpoints since currently it involves a bit of guesswork in my opinion (though I realize that is a lot of work, and I'd be happy with the former solution personally)

f-messner avatar Dec 28 '25 09:12 f-messner