I am studying TS. I'm trying to make simple calculator. How can I make it this calculator without switch statement? If the if statement is used, an error occurs in return type.

type Command = 'add' | 'substract' | 'multiply' | 'divide' | 'remainder';
const calculate = function (command: Command, num1: number, num2: number): number {
if (command === 'add') return num1 + num2;
if (command === 'substract') return num1 - num2;
if (command === 'multiply') return num1 * num2;
if (command === 'divide') return num1 / num2;
if (command === 'remainder') return num1 % num2;
// switch (command) {
// case 'add':
// return num1 + num2;
// case 'substract':
// return num1 - num2;
// case 'multiply':
// return num1 * num2;
// case 'divide':
// return num1 / num2;
// case 'remainder':
// return num1 % num2;
// default:
// throw Error('unknown command');
// }
};
console.log(calculate('add', 1, 3)); // 4
console.log(calculate('substract', 3, 1)); // 2
console.log(calculate('multiply', 4, 2)); // 8
console.log(calculate('divide', 4, 2)); // 2
console.log(calculate('remainder', 5, 2)); // 1