Skip to content

Commit 70b5a30

Browse files
authored
Merge pull request #15791 from Automattic/vkarpov15/gh-15779
types(query+model): use function overrides instead of `| Query<any, any>` to support using Query as filter
2 parents 59ed89e + 4035b51 commit 70b5a30

File tree

4 files changed

+392
-2
lines changed

4 files changed

+392
-2
lines changed

scripts/tsc-diagnostics-check.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
const fs = require('fs');
44

55
const stdin = fs.readFileSync(0).toString('utf8');
6-
const maxInstantiations = isNaN(process.argv[2]) ? 350000 : parseInt(process.argv[2], 10);
6+
const maxInstantiations = isNaN(process.argv[2]) ? 375000 : parseInt(process.argv[2], 10);
77

88
console.log(stdin);
99

test/types/queries.test.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,31 @@ function gh15671() {
827827
};
828828
}
829829

830+
async function gh15779() {
831+
type Entity = {
832+
id: string;
833+
age: number;
834+
name: string;
835+
};
836+
837+
function getV8FilterQuery(filter: QueryFilter<Entity>): QueryFilter<Entity> {
838+
return { ...filter, deletedAt: null };
839+
}
840+
841+
const v8Filter = getV8FilterQuery({ age: { $gt: 18 } });
842+
843+
v8Filter.name = 'test';
844+
845+
expectAssignable<typeof v8Filter.age>(42);
846+
expectNotAssignable<typeof v8Filter.age>('taco');
847+
848+
const TestModel = model('Test', new Schema({ age: Number, name: String }));
849+
const query = TestModel.find({ age: { $gt: 18 } });
850+
TestModel.find(query); // Should compile without errors
851+
TestModel.findOne(query);
852+
TestModel.deleteMany(query);
853+
}
854+
830855
async function gh15786() {
831856
interface IDoc {
832857
nmae: string;

0 commit comments

Comments
 (0)