Typescript index signature, change type of some properties

Viewed 32

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?

0 Answers
Related