I am looking to create a filtering system with various filters, each consisting of a label
, value
, and sometimes the options
variable. The inclusion of the type
property is intended for differentiation.
However, I have encountered an issue with the following code:
// TypeScript interface definitions...
The problem arises when checking the value of filters.swi.value
, which always returns false
. How can I ensure that it remains a boolean type as defined in the Filters
structure?
Attempting a simple conversion using as Filters
results in loss of IntelliSense for the filters
variable and transforms the value
property into a union type of boolean | string | string[]
.
An explicit cast like as SwitchFilter
raises an error due to 'variable label not being part of type SwitchFilter.'
Is it feasible to achieve this without directly casting the variable or should I consider an alternative approach?
EDIT
With my Plugin
class containing a filter
object and a search
method, every instance of Plugin
will have its own set of filters, requiring robust IntelliSense integration.
// TypeScript interfaces and classes definition...
In order to enhance IntelliSense within the search method based on individual filter values, I am seeking a solution that automatically assigns correct types to each filter item without manual conversions everywhere.
A tentative conditional logic utilizing:
// Conditional logic snippet...
and implementing the specific handling only in the search()
method as: