Currently diving into the world of TypeScript, I've embarked on the journey of organizing my code into separate files.
My primary file is structured as follows:
// calculator.ts
namespace Calculator {
console.log(Calculator.operate(1,2,"+"))
}
In a second file, I've defined the operate function:
// Operators.ts
namespace Calculator {
//..
export function operate(
a: number,
b: number,
operator: Operators
): number {
let answer: number = 0;
if (operator === "+") {
answer = add(a, b);
}
if (operator === "-") {
answer = subtract(a, b);
}
if (operator === "*") {
answer = multiply(a, b);
}
if (operator === "/") {
answer = divide(a, b);
}
return answer;
}
}
Executing the code in my browser using an HTML file with the script tag
<script src="../dist/calculator.js"></script>
However, upon running the code, a console error
Uncaught TypeError: Calculator.operate is not a function
surfaces.
What steps should I take to remedy this?