You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add TypeScript error when filtering on field not in schema
As a developer, I'd like the type system to catch errors I make, like
trying to query on a field that doesn't exist, or when I have made a
typo in an existing field name.
Previously, querying for these fields outside the schema would pass type
checks because the `Filter<TSchema>` type included a union with
`RootFilterOperators<WithId<TSchema>>`, and `RootFilterOperators` was
defined as `extends Document`. The BSON `Document` type itself is an
object with the index property `{ [key: string]: any }`, meaning that it
would match documents with any keys!
So, while our type checks would give us an error if we tried to pass the
wrong type into a filter expression, trying to use an unknown field name
would instead compare the value to the `any` type.
By removing the `extends Document` clause of the `RootFilterOperators`
type definition, we get much stronger guarantees from the `Filter` type.
0 commit comments