You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi!, We're trying to use egg.js in production with mongoose, but we notice a problem about the typing for Mongoose with egg-ts-mongoose plugin.
Mongoose itself has the typing solution(separate interface declaration or use ts-mongoose), and the egg-ts-helper also generated a correct type file of model files(interface IModel), Awesome!
But when using the model in service by this.ctx.model, the model type is referred to the egg.Context.model in egg-ts-mongoose/index.d.ts(https://github.com/eggjs/egg-mongoose/blob/master/index.d.ts#L28), which type is [key: string]: mongoose.Model<any>.
So in the service, the model type is Model<any>, it's very stupid! and the solution also very easy, just override the type of context.model to IModel, by edit typing/index.d.ts as below:
(Edit the typing/model/index.d.ts should has same result)
I think this job can not be done by egg-mongoose, because the interface IModel is a generated file.
I'm using WebStorm 2020.2, but I think the VSCode should has the same problem, because the context.model type refer to egg-mongoose seems a correct behavior or maybe I wrong :D
Thanks!
The text was updated successfully, but these errors were encountered:
Hi!, We're trying to use egg.js in production with mongoose, but we notice a problem about the typing for Mongoose with
egg-ts-mongoose
plugin.Mongoose itself has the typing solution(separate interface declaration or use
ts-mongoose
), and theegg-ts-helper
also generated a correct type file of model files(interfaceIModel
), Awesome!But when using the model in service by
this.ctx.model
, the model type is referred to theegg.Context.model
inegg-ts-mongoose/index.d.ts
(https://github.com/eggjs/egg-mongoose/blob/master/index.d.ts#L28), which type is[key: string]: mongoose.Model<any>
.So in the service, the model type is
Model<any>
, it's very stupid! and the solution also very easy, just override the type ofcontext.model
toIModel
, by edittyping/index.d.ts
as below:(Edit the
typing/model/index.d.ts
should has same result)I think this job can not be done by
egg-mongoose
, because the interfaceIModel
is a generated file.I'm using WebStorm 2020.2, but I think the VSCode should has the same problem, because the
context.model
type refer toegg-mongoose
seems a correct behavior or maybe I wrong :DThanks!
The text was updated successfully, but these errors were encountered: