Is it possible to make TypeScript don’t compile when writing a Mongoose query that does not contain valid fields? For example, given the schema and the model below
const personSchema = new mongoose.Schema({
name: { type: String, required: true },
name: { type: Number, required: true },
})
const person = mongoose.model('PersonCollection', personSchema);
I want TypeScript to complain when I write this query since randomProperty
does not exist on personSchema
/ person
.
person.find({ randomProperty: 123 })
I see that Mongoose allows querying on unknown properties since strictQuery
is false by default in the migration guide to Mongoose 7. But I find it weirder that Mongoose don’t complain when querying on unknown properties.
Additional context
I use automatic type interference by the way since that is recommended by Mongoose. And yes I have "strict": true
in my tsconfig
.
Versions
- Mongoose 8.4.0
- MongoDB 6.0
- TypeScript 5.4.2