Skip to content

Commit 62223bf

Browse files
authored
Merge pull request #14235 from amitbeck/types/schema_omit
types(schema): add missing `omit()` method
2 parents 2657417 + 9c823cd commit 62223bf

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

test/types/schema.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,3 +1379,15 @@ function gh14147() {
13791379
const doc = new AffiliateModel();
13801380
expectType<bigint>(doc.balance);
13811381
}
1382+
1383+
function gh14235() {
1384+
interface IUser {
1385+
name: string;
1386+
age: number;
1387+
}
1388+
1389+
const userSchema = new Schema<IUser>({ name: String, age: Number });
1390+
1391+
userSchema.omit<Omit<IUser, 'age'>>(['age']);
1392+
}
1393+

types/index.d.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ declare module 'mongoose' {
302302
/** The original object passed to the schema constructor */
303303
obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>, EnforcedDocType>;
304304

305+
/** Returns a new schema that has the `paths` from the original schema, minus the omitted ones. */
306+
omit<T = this>(paths: string[], options?: SchemaOptions): T;
307+
305308
/** Gets/sets schema paths. */
306309
path<ResultType extends SchemaType = SchemaType<any, THydratedDocumentType>>(path: string): ResultType;
307310
path<pathGeneric extends keyof EnforcedDocType>(path: pathGeneric): SchemaType<EnforcedDocType[pathGeneric]>;

0 commit comments

Comments
 (0)