I have a similar function like this one:
export const bar = function () {
const myItem = new MyItem();
return function bar(param1?: number, param2?: string): void{
...
};
}();
Where myItem
is a variable that I use as a temporary inside the function, and I capture it in this way to avoid allocating it every time.
I wanted to add overloads to create 2 different versions:
export function bar(): void;
export function bar(param1: number): void;
It doesn't matter if this overload makes sense, it's just for demonstration purposes.
I wanted to know if there is a way to overload bar
declared in this way, or if I have to make the "static" variable myItem
a module variable.
I prefer to keep it "local" to the function if possible, but haven't been able to find a way yet.