Skip to content

Commit

Permalink
test(index.d.ts): repro #9989
Browse files Browse the repository at this point in the history
  • Loading branch information
vkarpov15 committed Mar 18, 2021
1 parent fba3457 commit 4d954f3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion test/typescript/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const Test = model<ITest, Model<ITest, QueryHelpers>>('Test', schema);
Test.find().byName('test').orFail().exec().then(console.log);

Test.count({ name: /Test/ }).exec().then((res: number) => console.log(res));
Test.findOne({ 'docs.id': 42 }).exec().then(console.log);

// ObjectId casting
Test.find({ parent: new Types.ObjectId('0'.repeat(24)) });
Expand Down Expand Up @@ -74,4 +75,16 @@ query instanceof Query;

// Chaining
Test.findOne().where({ name: 'test' });
Test.where().find({ name: 'test' });
Test.where().find({ name: 'test' });

// Super generic query
function testGenericQuery(): void {
interface CommonInterface<T> extends Document {
something: string;
content: T;
}

async function findSomething<T>(model: Model<CommonInterface<T>>): Promise<CommonInterface<T>> {
return model.findOne({something: 'test'}).orFail().exec();
}
}

0 comments on commit 4d954f3

Please sign in to comment.