Looking to work with a legacy API that has the following structure (playground link)...
type Command1 = {
cmd: "my first command",
arg1: string,
arg2: boolean
}
type Command2 = {
cmd: "my second command",
foo: string,
bar: number
}
type Command = Command1 | Command2
function execute(cmd: Command["cmd"], args:any /* would like to strongly type this */) {
console.log(args)
}
execute("my first command", {/* oops missing props */})
Seeking a method to ensure type checking for the args
parameter of the execute
function without altering the function's parameter list. Any suggestions?
Appreciate any insights. Thank you.