I'm trying to define a query object dynamically (which is used for some MongoDB method calling).
let query = {
category: { $exists: true, $ne: [] }
}
if (isAdmin) {
query = {
category: { $exists: true },
isFinalized: { $exists: false }
}
} else if (isEditor) {
query = {
category: { $in: specialisation }
}
}
It is only a small part of the object generation.
But with that I do get the TS error Object literal may only specify known properties for isFinalized and category.$in.
So how should I handle this correctly?
let query = {
category: { $exists: true, $ne: [], $in: undefined },
isFinalized: undefined
}
This seems very ugly to me.
queryhave a type or is Typescript complaining about a random object?queryexplicitly either in that case?