A bit hard to explain it in the title but basically, I'd like to be able to declare a type array of fixed length strings from 1 to N:
interface Command {
[key: string]: (args: [string, ...string[]]) => boolean;
}
const cmd: Command = {
TEST: (args: [string, string]) => args[0] === args[1],
TEST2: (args: [string]) => args[0] === 'hello'
}
so this doesn't work as [string, string] is different from string[]:
Type '(args: [string]) => boolean' is not assignable to type '(args: [string, ...string[]]) => boolean'.
A solution could be to define like all kind of arguments:
interface Command {
[key: string]: (args: [string] | [string, string] | [string, string, string]) => boolean;
}
But a bit too verbose for something simple (agreed it can be encapsulated in an interface), anyway is there another elegant solution to this that I'm not seeing?
Thanks,
Commandto look like. Can you show how you would plan to use a valuecof typeCommand? Say, you have the functionc.f... are you allowed to call it withc.f(["hello"])? Can you call it withc.f(["hello","goodbye"])?