Skip to content

Commit

Permalink
Improve ApplyBasicQueryCasting type to improve find FN suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
mohammad0-0ahmad committed Jun 3, 2022
1 parent e75d4b6 commit ff2bf3e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions test/types/models.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,10 @@ export async function m0_0aModel() {
expectType<M0_0aAutoTypedSchemaType['schema']['userName']>(testDoc1.userName);
expectType<M0_0aAutoTypedSchemaType['schema']['description']>(testDoc1.description);

const testDoc2 = await AutoTypeModel.findOne({ userName: 'M0_0a' });
expectType<M0_0aAutoTypedSchemaType['schema']['userName'] | undefined>(testDoc2?.userName);
expectType<M0_0aAutoTypedSchemaType['schema']['description'] | undefined>(testDoc2?.description);

/* -------------------------------------------------------------------------- */
/* Model-statics-functions-test */
/* -------------------------------------------------------------------------- */
Expand Down
2 changes: 1 addition & 1 deletion types/query.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
declare module 'mongoose' {
import mongodb = require('mongodb');

type ApplyBasicQueryCasting<T> = T | T[] | any;
export type ApplyBasicQueryCasting<T, defaultT = T | T[] | {}> = T extends any[] ? T[0] & defaultT: defaultT;
type Condition<T> = ApplyBasicQueryCasting<T> | QuerySelector<ApplyBasicQueryCasting<T>>;

type _FilterQuery<T> = {
Expand Down

0 comments on commit ff2bf3e

Please sign in to comment.