Skip to content

Commit

Permalink
Merge pull request #11588 from Automattic/bug/types/update-query
Browse files Browse the repository at this point in the history
Bug/types/update query
  • Loading branch information
vkarpov15 committed Mar 27, 2022
2 parents cce977d + 781dcb3 commit bfa65e9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions test/types/models.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Schema, Document, Model, Types, connection, model } from 'mongoose';
import { expectError } from 'tsd';
import { UpdateQuery, Schema, Document, Model, Types, connection, model } from 'mongoose';
import { expectError, expectType } from 'tsd';

function conventionalSyntax(): void {
interface ITest extends Document {
Expand Down Expand Up @@ -211,4 +211,18 @@ function inheritance() {

Project.createCollection({ expires: '5 seconds' });
Project.createCollection({ expireAfterSeconds: 5 });
expectError(Project.createCollection({ expireAfterSeconds: '5 seconds' }));
expectError(Project.createCollection({ expireAfterSeconds: '5 seconds' }));


function update() {
interface IUser {
name: string;
age: number;
isActive: boolean;
}
const update: UpdateQuery<IUser> = {};

expectType<string | undefined>(update.name);
expectType<number | undefined>(update.age);
expectType<boolean | undefined>(update.isActive);
}
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,7 @@ declare module 'mongoose' {
* { age: 30 }
* ```
*/
export type UpdateQuery<T> = _UpdateQuery<_UpdateQueryDef<T>> & AnyObject;
export type UpdateQuery<T> = Partial<T> & _UpdateQuery<_UpdateQueryDef<T>> & AnyObject;

export type DocumentDefinition<T> = {
[K in keyof Omit<T, Exclude<keyof Document, '_id' | 'id' | '__v'>>]:
Expand Down

0 comments on commit bfa65e9

Please sign in to comment.