From 9c823cddcee1366be73b647118040f43cf55d054 Mon Sep 17 00:00:00 2001 From: Amit Beckenstein Date: Sat, 6 Jan 2024 00:24:31 +0200 Subject: [PATCH] types(schema): add missing omit() method --- test/types/schema.test.ts | 12 ++++++++++++ types/index.d.ts | 3 +++ 2 files changed, 15 insertions(+) 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;