I have a function that accepts an argument of either an object or an array.
const handleScenarioChange = (scenario: Scenario | Scenario[]) => {
if (isArray(scenario)) {
const scenarios = [...state.selectedScenarios, ...scenario];
const uniqueScenarios = removeDuplicateScenarios(scenarios);
setState({ selectedScenarios: sortBy(uniqueScenarios, ['Name']) });
} else {
// If scenario is not an array, it means this is adding a tag
const scenarios = [...state.selectedScenarios, scenario];
const uniqueScenarios = removeDuplicateScenarios(scenarios);
setState({ selectedScenarios: sortBy(uniqueScenarios, ['Name']) });
}
};
As seen above, I am creating uniqueScenarios and updating the state within an if and else block. However, I aim to achieve the same result using a ternary operator.
I attempted
const scenarios = [...state.selectedScenarios, ...(isArray(scenario)) ? ...scenario : scenario];
const uniqueScenarios = removeDuplicateScenarios(scenarios);
setState({ selectedScenarios: sortBy(uniqueScenarios, ['Name']) });
The target for my compilerOptions.target in my tsconfig.json file is es5. I switched it to es6 but the issue persists. Seeking guidance on this matter.
Find Stackblitz link here