Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types(schema): add missing omit() method #14235

Merged
merged 1 commit into from Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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