clipanion
clipanion copied to clipboard
Typepanion Literal Number and Option.String do not play nice together
// don't use well known ports
const isPort = isOneOf(
[isLiteral(0), cascade(isNumber(), isInteger(), isPositive(), isInInclusiveRange(1024, 65535))],
{ exclusive: true },
)
export class App extends Command {
readonly port = Option.String('--port', '0', { validator: isPort })
static readonly paths = [Command.Default]
}
unfortunately OptionString
cannot take a number, and so literal 0 will fail
❯ yarn workspace @cof/e1-fake-chamber-of-secrets serve
Usage Error: Invalid value for port:
- .#1: Expected 0 (got "0")
- .#2: Expected to be in the [1024; 65535] range (got 0)
I guess my suggestion for a fix would be to allow a subset of primitives to Option.String
fortunately express seems ok with the string