If you want only a certain value of the parameter that can be used inside your TypeScript function then you can use the literal type to do so as shown in the following lines of code.
type allownumber = 1 | 2 | 123 function add(number1:allownumber, number2:allownumber) : number { return number1 + number2 } console.log(add(1,123)) console.log(add(1,6))
The TypeScript program above will generate the following error during compilation because 6 is not the permitted parameter inside the add function.
error TS2345: Argument of type '6' is not assignable to parameter of type 'allownumber'. 10 console.log(add(1,6))
The literal type is very useful when it comes to limiting the use of parameters within a TypeScript function!