Let's say I have a function with multiple optional parameters.
Why is there no type guard based on the function arity through the arguments
keyword and how to solve this without changing the implementation and without ugly casts?
function test(arg0?: string, arg1?: string, arg2?: string) {
if (arguments.length === 1) {
// I expect arg0 to be of type string instead of string | undefined
}
if (arguments.length === 2) {
// I expect arg0 and arg1 to be of type string instead of string | undefined
}
if (arguments.length === 3) {
// I expect arg0, arg1 and arg2 to be of type string instead of string | undefined
}
}