It's a bit difficult for me to explain this question clearly in words.
So i've writed a demo
let initialized = false;
let counter: number | null = null;
export function initializer(...args: any){
// ...
counter = 1;
initialized = true;
}
function initCheckWrapper(func: (...args: any) => any) {
return (...args: Parameters<typeof func>) => {
if (initialized !== true)
throw new TypeError('module is not initialized');
return func(...args);
}
}
function count() {
counter++; // "counter" could be null
}
const wrappedCount = initCheckWrapper(count);
export { wrappedCount as count };
how to make counter not to be a number | null but just number in initCheckWrapper(count) scope?