In a method, I have a type with a possible value of an array. However, before I access the argument, I check to ensure that the argument isn't an array.
I still get the following error (excerpt) on line this.setState({ cuisine });:
Type 'readonly SelectOption[]' is missing the following properties from type 'SelectOption': value, label
When I hover over cuisine on the error line, the type determined by VS Code is SelectOption | readonly SelectOption[]
Here's the code:
interface SelectOption {
value: number | string;
label: string
}
private onCuisineChange(cuisine: ValueType<SelectOption>): void {
if (Array.isArray(cuisine) && cuisine.length > 1) {
throw new Error(`Expected cuisine to be an object, but got ${cuisine}`);
}
if (cuisine) {
this.setState({ cuisine });
} else {
}
}
Using TS version 3.5.3