Closed infiniityr closed 2 years ago
I'm not getting your error message but I am getting an error message: type instantiation is deep and possibly infinite.
At least the error is more explicite in your case ! Do you have an idea why it says so ?
I can not reproduce it. I added your code into schema.test.ts
function gh11831() {
interface ISearchableModel<T = ISearchable> extends Model<T> {
fuzzySearch(searchterm: string, limited: boolean): Promise<T[]>
searchables(): string[]
searchableFields(): string[]
}
interface ISearchable extends Document {
search: string[]
searchables(): string[]
}
const searchPlugin = (schema: Schema<ISearchable, Model<ISearchable>>, opts?: any) => { }
interface IMyObject extends ISearchable { }
interface IMyObjectModel extends ISearchableModel<IMyObject> {
}
const MyObjectSchema = new Schema<IMyObject, IMyObjectModel>({
// Definition of the schema
})
MyObjectSchema.plugin(searchPlugin);
}
Can you give me a working snippet, which results in your error?
I don't understand, I can't reproduce my error anymore... It looks like the version of Typescript have been upgraded from 4.6.4 to 4.7.2.
@IslandRhythms Have you managed to reproduce it ? Or partially reproduce it ?
Here is my environment :
Do you want to request a feature or report a bug?
Report a bug
What is the current behavior?
When creating a plugin in Typescript, It is not possible to specify in the function a custom Model signature.
If the current behavior is a bug, please provide the steps to reproduce.
In my plugin
When I want to use the plugin
I have the following Typescript error.
'Schema<IMyObject, Model<IMyObject, any, any, any>, {}, {}>' is not assignable to type 'Schema<ISearchable, ISearchableModel<ISearchable>, {}, {}>'
What is the expected behavior?
This should work because
ISearchableModel
extendsModel
.From what I seen, the issue is only on the
Model<IMyObject>
part.If I set the signature of my plugin function as follow, it works for Typescript (but not for me...)
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
NodeJS : v16.13.0 Mongoose : v6.3.4