diff --git a/test/types/schema.test.ts b/test/types/schema.test.ts index 2e12d92eb7e..43ba2253f05 100644 --- a/test/types/schema.test.ts +++ b/test/types/schema.test.ts @@ -1379,3 +1379,15 @@ function gh14147() { const doc = new AffiliateModel(); expectType(doc.balance); } + +function gh14235() { + interface IUser { + name: string; + age: number; + } + + const userSchema = new Schema({ name: String, age: Number }); + + userSchema.omit>(['age']); +} + diff --git a/types/index.d.ts b/types/index.d.ts index 456d392944c..987d35c8117 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -302,6 +302,9 @@ declare module 'mongoose' { /** The original object passed to the schema constructor */ obj: SchemaDefinition, EnforcedDocType>; + /** Returns a new schema that has the `paths` from the original schema, minus the omitted ones. */ + omit(paths: string[], options?: SchemaOptions): T; + /** Gets/sets schema paths. */ path>(path: string): ResultType; path(path: pathGeneric): SchemaType;