Skip to content

Commit

Permalink
feat(types): allow calling Model.discriminator() with options
Browse files Browse the repository at this point in the history
Re: #12472
  • Loading branch information
vkarpov15 committed Oct 9, 2022
1 parent 3f2c3cb commit 2a9208b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
6 changes: 6 additions & 0 deletions test/types/discriminator.test.ts
Expand Up @@ -18,6 +18,12 @@ const doc: IDiscriminatorTest = new Disc({ name: 'foo', email: 'hi' });
doc.name = 'bar';
doc.email = 'hello';

const Disc2 = Base.discriminator<IDiscriminatorTest>(
'Disc2',
new Schema({ email: { type: String } }),
{ value: 'test', mergeHooks: false }
);

function test(): void {
enum CardType {
Artifact = 'artifact',
Expand Down
11 changes: 9 additions & 2 deletions types/models.d.ts
@@ -1,10 +1,17 @@
declare module 'mongoose' {
import mongodb = require('mongodb');

export interface DiscriminatorOptions {
value?: string | number | ObjectId;
clone?: boolean;
overwriteModels?: boolean;
mergeHooks?: boolean;
}

export interface AcceptsDiscriminator {
/** Adds a discriminator type. */
discriminator<D>(name: string | number, schema: Schema, value?: string | number | ObjectId): Model<D>;
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string | number | ObjectId): U;
discriminator<D>(name: string | number, schema: Schema, value?: string | number | ObjectId | DiscriminatorOptions): Model<D>;
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string | number | ObjectId | DiscriminatorOptions): U;
}

interface MongooseBulkWriteOptions {
Expand Down

0 comments on commit 2a9208b

Please sign in to comment.