Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test/types/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,27 @@ async function registerPlugin(): Promise<void> {
console.log(test3.fullName);
console.log(test3.doSomething());
}

function gh16086() {
interface Doc {
name: string;
}

type DocInstance = HydratedDocument<Doc>;

interface ModelWithStatic extends Model<Doc, {}, {}, {}, DocInstance> {
findByName(name: string): Promise<Doc>;
}

function plugin(schema: Schema): void {
schema.pre('save', function() {
void this;
});
}

const schema = new Schema<Doc, ModelWithStatic>({
name: { type: String, required: true }
});

schema.plugin(plugin);
}
1 change: 1 addition & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ declare module 'mongoose' {

/** Registers a plugin for this schema. */
plugin<PFunc extends PluginFunction<DocType, TModelType, any, any, any, any>, POptions extends Parameters<PFunc>[1] = Parameters<PFunc>[1]>(fn: PFunc, opts?: POptions): this;
plugin<PFunc extends PluginFunction<DocType, Model<DocType, any, any, any, any, any>, any, any, any, any>, POptions extends Parameters<PFunc>[1] = Parameters<PFunc>[1]>(fn: PFunc, opts?: POptions): this;

/** Defines a post hook for the model. */

Expand Down
Loading