Hello all,
I have managed to confuse myself again… I think it is fairly intuitive what I am trying to achieve, but TS disagrees:
const obj: BaseType = {
filters: [
{
filterType: "PRICE_FILTER",
minPrice: "0.00000100",
maxPrice: "100000.00000000",
tickSize: "0.00000100",
},
{
filterType: "PERCENT_PRICE",
multiplierUp: "1.3000",
multiplierDown: "0.7000",
avgPriceMins: 5,
},
}
interface BaseType {
filter: SymbolFilterTypes[];
}
type SymbolFilterTypes =
| PriceFilter
| PercentPrice;
enum FilterTypes {
PRICE_FILTER = "PRICE_FILTER",
PERCENT_PRICE = "PERCENT_PRICE"
}
type PriceFilter = {
filterType: FilterTypes.PRICE_FILTER;
minPrice: string;
maxPrice: string;
tickSize: string;
};
type PercentPrice = {
filterType: FilterTypes.PERCENT_PRICE;
multiplierUp: string;
multiplierDown: string;
avgPriceMins: number;
};
However, I get this complaint:
Type '"PRICE_FILTER"' is not assignable to type 'FilterTypes'.deno-ts(2322)
Any help understanding the best semantic way to do this would be appreciated.