Programming Digits
type NumType = 1 | 2 | 3 | 4 | 5;
function numFunc(number: NumType) {
console.log("Number selected: ", number);
}
const randomNumber = Math.floor(Math.random() * 10);
if (0 < randomNumber && randomNumber < 6) {
numFunc(randomNumber)
}
When dealing with this code, TypeScript throws an error
Argument of type 'number' is not assignable to parameter of type 'NumType'
Is there a way to enforce that TypeScript compiler confirms that randomNumber
is of type NumType
?