1

I'd like to be able to use index signatures to allow any string property in an object, but override specific properties with different types, something like:

type Filter = {
    eq?: string | number;
    // other operators
}

type Filters = {
    [field: string]: Filter[];
    $or: Filters[]; // does not work
    $and: Filters[]; // does not work
}

The interface is similar to MongoDb's query client.

Answers here almost get me to what I want, one of the answers lets you subtract (but not override) a property. TypeScript: object with any keys except one

Is there any way to do what I want here?

UnknownBeef
  • 418
  • 3
  • 17
  • 1
    There is no specific type in TypeScript that works this way, unfortunately. See the answer to the linked question for the various options. Because of the multiple properties and the recursive definition, I'd *strongly* suggest you refactor so that the arbitrarily-named fields are pushed down a level. – jcalz Jun 24 '22 at 19:32

0 Answers0