Let's say I have the following function:
function repeat(times: number, cb: (index: number) => any) {
for (let i = 0; i < times; i++) {
cb(i);
}
}
repeat(3, (i) => console.log(i)); // logs 0 1 2
I want to be able to assert at compile-time that the given number for the number of times to call the callback is an integer. I know that you can do this by taking in a bigint, however, I would rather not allow for numbers to be larger than the regular number limit because the function would most likely not even finish. Is there any way to make TypeScript error when the number provided is not an integer?