【发布时间】:2018-02-21 07:07:00
【问题描述】:
那么有谁知道为什么我在使用 mongoose 钩子并引用 this 时可能会收到 Typescript 错误。我没有使用箭头函数,我知道它的词法范围问题,但即使是这样的匿名函数:
UserSchema.pre("save", function(next) {
console.log(this.password);
next();
});
确切的错误信息是
'this' implicitly has type 'any' because it does not have a type annotation.
有人知道如何解决这个问题吗?
顺便说一句,我使用的是 Typescript 2.5.2 / NodeJS 8.2.1
谢谢!
【问题讨论】:
-
这个问题可能会有所帮助:stackoverflow.com/questions/41944650/…
标签: typescript mongoose