Skip to content

Commit

Permalink
Merge pull request #14235 from amitbeck/types/schema_omit
Browse files Browse the repository at this point in the history
types(schema): add missing `omit()` method
  • Loading branch information
vkarpov15 committed Jan 6, 2024
2 parents 2657417 + 9c823cd commit 62223bf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions test/types/schema.test.ts
Expand Up @@ -1379,3 +1379,15 @@ function gh14147() {
const doc = new AffiliateModel();
expectType<bigint>(doc.balance);
}

function gh14235() {
interface IUser {
name: string;
age: number;
}

const userSchema = new Schema<IUser>({ name: String, age: Number });

userSchema.omit<Omit<IUser, 'age'>>(['age']);
}

3 changes: 3 additions & 0 deletions types/index.d.ts
Expand Up @@ -302,6 +302,9 @@ declare module 'mongoose' {
/** The original object passed to the schema constructor */
obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>, EnforcedDocType>;

/** Returns a new schema that has the `paths` from the original schema, minus the omitted ones. */
omit<T = this>(paths: string[], options?: SchemaOptions): T;

/** Gets/sets schema paths. */
path<ResultType extends SchemaType = SchemaType<any, THydratedDocumentType>>(path: string): ResultType;
path<pathGeneric extends keyof EnforcedDocType>(path: pathGeneric): SchemaType<EnforcedDocType[pathGeneric]>;
Expand Down

0 comments on commit 62223bf

Please sign in to comment.