Let's say I have the following function for finding the square root of a number:
function sqrt(n: number): number {
return Math.sqrt(n);
}
I would like to find a way to assert that the given number is non-negative. Currently, the Math.sqrt function returns NaN for negative numbers which can introduce sneaky bugs so I'd rather catch these simply errors at compile-time. Is there any way to make TypeScript error when the given number is not positive?