Is there a more graceful way to declare a Typescript array type where the last element is optional?
const example = (arr: [string, string, any | undefined]) => console.log(arr)
example(['foo', 'bar'])
When I call the example(...)
function, TypeScript shows the following error message:
Error: Argument of type '[string, string]' is not assignable to parameter of type '[string, string, any]'.
Property '2' is missing in type '[string, string]' but required in type '[string, string, any]'.(2345)