我正在使用node v6.10.3
,typescript v2.3.4
和jsonwebtoken v7.4.1
。直到今天,我用的是从@types/jsonwebtoken v7.2.0
类型的信息,但我升级到@types/jsonwebtoken v7.2.1
,现在当我跑我的应用中提供了错误:@ types/jsonwebtoken 7.2.1给出了奇怪的类型错误。为什么?
src/reports/password-reset/password-reset.report.ts(18,23): error TS2345: Argument of type '{ ownerId: string; passwordResetToken: boolean; }' is not assignable to parameter of type 'string | object | Buffer'.
Object literal may only specify known properties, and 'ownerId' does not exist in type 'string | object | Buffer'.
有关的代码行:
let token = sign({ownerId:passwordResetRequest.ownerId, passwordResetToken: true },
configuration.secret, {
expiresIn: timeToLiveInSeconds
});
这错误不会出现@types/jsonwebtoken v7.2.0
,只有v7.2.1
。
奇怪的是,如果我在Visual Studio Code(TypeScript的相同版本)中构建我的项目,它会显示相同的错误,但是当我单击错误并转到相关文件时,错误消失,VS Code很高兴与语法。
此外,错误消息告诉我,我的对象{ownerId:passwordResetRequest.ownerId, passwordResetToken: true }
不能传递给string | object | Buffer
类型的参数,但它显然是一个对象。我不知道为什么它甚至关心对象的内容是什么。
另请注意,它工作正常 - 就像实际的jsonwebtoken
库很好 - 它只是@type
信息,造成在构建过程中的问题。
所以我刚刚恢复到@types/jsonwebtoken v7.2.0
,一切正常。不是一个大问题,但是发生了什么?