mongoose: remove null from result type when doc must exist

This commit is contained in:
Ethan Resnick
2018-03-05 23:25:39 -05:00
parent 469e4afa8c
commit dc4147a0b6
4 changed files with 25 additions and 0 deletions

View File

@@ -1545,6 +1545,9 @@ declare module "mongoose" {
callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery<DocType | null, DocType>;
findOneAndUpdate(query: any | Query<any>, update: any,
callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery<DocType | null, DocType>;
findOneAndUpdate(query: any | Query<any>, update: any,
options: { upsert: true, new: true } & QueryFindOneAndUpdateOptions,
callback?: (err: any, doc: DocType, res: any) => void): DocumentQuery<DocType, DocType>;
findOneAndUpdate(query: any | Query<any>, update: any, options: QueryFindOneAndUpdateOptions,
callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery<DocType | null, DocType>;
@@ -2520,6 +2523,9 @@ declare module "mongoose" {
findByIdAndUpdate(): DocumentQuery<T | null, T>;
findByIdAndUpdate(id: any | number | string, update: any,
callback?: (err: any, res: T | null) => void): DocumentQuery<T | null, T>;
findByIdAndUpdate(id: any | number | string, update: any,
options: { upsert: true, new: true } & ModelFindByIdAndUpdateOptions,
callback?: (err: any, res: T) => void): DocumentQuery<T, T>;
findByIdAndUpdate(id: any | number | string, update: any,
options: ModelFindByIdAndUpdateOptions,
callback?: (err: any, res: T | null) => void): DocumentQuery<T | null, T>;
@@ -2565,6 +2571,9 @@ declare module "mongoose" {
findOneAndUpdate(): DocumentQuery<T | null, T>;
findOneAndUpdate(conditions: any, update: any,
callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery<T | null, T>;
findOneAndUpdate(conditions: any, update: any,
options: { upsert: true, new: true } & ModelFindOneAndUpdateOptions,
callback?: (err: any, doc: T, res: any) => void): DocumentQuery<T, T>;
findOneAndUpdate(conditions: any, update: any,
options: ModelFindOneAndUpdateOptions,
callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery<T | null, T>;

View File

@@ -758,6 +758,7 @@ query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, {
}, cb);
query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, cb);
query.findOneAndUpdate({name: 'aa'}, {name: 'bb'});
query.findOneAndUpdate({}, {}, { upsert: true, new: true });
query.findOneAndUpdate({name: 'bb'}, cb);
query.findOneAndUpdate({name: 'bb'});
query.findOneAndUpdate(cb);
@@ -1387,6 +1388,7 @@ MongoModel.findByIdAndRemove(999);
MongoModel.findByIdAndRemove();
MongoModel.findByIdAndUpdate(999, {}, {}, cb);
MongoModel.findByIdAndUpdate(999, {}, {});
MongoModel.findByIdAndUpdate(999, {}, { upsert: true, new: true });
MongoModel.findByIdAndUpdate(999, {}, cb);
MongoModel.findByIdAndUpdate(999, {});
MongoModel.findByIdAndUpdate();
@@ -1415,6 +1417,7 @@ MongoModel.findOneAndRemove({});
MongoModel.findOneAndRemove();
MongoModel.findOneAndUpdate({}, {}, {}, cb);
MongoModel.findOneAndUpdate({}, {}, {});
MongoModel.findOneAndUpdate({}, {}, { upsert: true, new: true });
MongoModel.findOneAndUpdate({}, {}, cb);
MongoModel.findOneAndUpdate({}, {});
MongoModel.findOneAndUpdate();

View File

@@ -1602,6 +1602,9 @@ declare module "mongoose" {
callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery<DocType | null, DocType>;
findOneAndUpdate(query: any | Query<any>, update: any,
callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery<DocType | null, DocType>;
findOneAndUpdate(query: any | Query<any>, update: any,
options: { upsert: true, new: true } & QueryFindOneAndUpdateOptions,
callback?: (err: any, doc: DocType, res: any) => void): DocumentQuery<DocType, DocType>;
findOneAndUpdate(query: any | Query<any>, update: any, options: QueryFindOneAndUpdateOptions,
callback?: (err: any, doc: DocType | null, res: any) => void): DocumentQuery<DocType | null, DocType>;
@@ -2528,6 +2531,9 @@ declare module "mongoose" {
findByIdAndUpdate(): DocumentQuery<T | null, T>;
findByIdAndUpdate(id: any | number | string, update: any,
callback?: (err: any, res: T | null) => void): DocumentQuery<T | null, T>;
findByIdAndUpdate(id: any | number | string, update: any,
options: { upsert: true, new: true } & ModelFindByIdAndUpdateOptions,
callback?: (err: any, res: T) => void): DocumentQuery<T, T>;
findByIdAndUpdate(id: any | number | string, update: any,
options: ModelFindByIdAndUpdateOptions,
callback?: (err: any, res: T | null) => void): DocumentQuery<T | null, T>;
@@ -2573,6 +2579,9 @@ declare module "mongoose" {
findOneAndUpdate(): DocumentQuery<T | null, T>;
findOneAndUpdate(conditions: any, update: any,
callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery<T | null, T>;
findOneAndUpdate(conditions: any, update: any,
options: { upsert: true, new: true } & ModelFindOneAndUpdateOptions,
callback?: (err: any, doc: T, res: any) => void): DocumentQuery<T, T>;
findOneAndUpdate(conditions: any, update: any,
options: ModelFindOneAndUpdateOptions,
callback?: (err: any, doc: T | null, res: any) => void): DocumentQuery<T | null, T>;

View File

@@ -743,6 +743,8 @@ query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, {
}, cb);
query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, cb);
query.findOneAndUpdate({name: 'aa'}, {name: 'bb'});
query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, { });
query.findOneAndUpdate({name: 'aa'}, {name: 'bb'}, { upsert: true, new: true });
query.findOneAndUpdate({name: 'bb'}, cb);
query.findOneAndUpdate({name: 'bb'});
query.findOneAndUpdate(cb);
@@ -1371,6 +1373,7 @@ MongoModel.findByIdAndRemove(999);
MongoModel.findByIdAndRemove();
MongoModel.findByIdAndUpdate(999, {}, {}, cb);
MongoModel.findByIdAndUpdate(999, {}, {});
MongoModel.findByIdAndUpdate(999, {}, { new: true, upsert: true }, cb);
MongoModel.findByIdAndUpdate(999, {}, cb);
MongoModel.findByIdAndUpdate(999, {});
MongoModel.findByIdAndUpdate();
@@ -1399,6 +1402,7 @@ MongoModel.findOneAndRemove({});
MongoModel.findOneAndRemove();
MongoModel.findOneAndUpdate({}, {}, {}, cb);
MongoModel.findOneAndUpdate({}, {}, {});
MongoModel.findOneAndUpdate({}, {}, { upsert: true, new: true });
MongoModel.findOneAndUpdate({}, {}, cb);
MongoModel.findOneAndUpdate({}, {});
MongoModel.findOneAndUpdate();