My interface has the capability to accept either a number
or an array
as a value. The array format always starts with a number followed by a string, for example:
[136237, "Name of something"]
.
The type is defined as follows:
interface SaleOrder {
...,
partner_id?: [number, string] | number;
}
In this particular scenario, the property arrives in the form of an array.
In my code implementation, I have:
const { name, partner_id, id, amount_total } = saleOrder as SaleOrder;
const order = {
"Name": name as string,
"Customer Name": partner_id[1] as string,
"Total Sale": amount_total as number
}
However, even though it is valid to use '1' as an index in an array, VS Code displays a warning. Why is that?