Getting an error when calling "jsonwebtoken.verify"
See original GitHub issueJust ran the generator. The generated app is throwing an error src/shared/JwtService.ts - the jsonwebtoken.verify has parameters that aren’t matching.
I’m running Win10, Node v12, Typescript 3.6.3.
The error message:
`src/shared/JwtService.ts:45:51 - error TS2769: No overload matches this call. Overload 1 of 3, ‘(token: string, secretOrPublicKey: Secret, options?: VerifyOptions | undefined): string | object’, gave the following error. Type ‘(err: VerifyErrors, decoded: string | object) => void’ has no properties in common with type ‘VerifyOptions’. Overload 2 of 3, ‘(token: string, secretOrPublicKey: string | Buffer | { key: string | Buffer; passphrase: string; } | GetPublicKeyOrSecret, callback?: VerifyCallback | undefined): void’, gave the following error. Argument of type ‘(err: VerifyErrors, decoded: object | string) => void’ is not assignable to parameter of type ‘VerifyCallback’. Types of parameters ‘err’ and ‘err’ are incompatible. Type ‘JsonWebTokenError | NotBeforeError | TokenExpiredError | null’ is not assignable to type ‘VerifyErrors’. Type ‘null’ is not assignable to type ‘VerifyErrors’. Overload 3 of 3, ‘(token: string, secretOrPublicKey: string | Buffer | { key: string | Buffer; passphrase: string; } | GetPublicKeyOrSecret, options?: VerifyOptions | undefined, callback?: VerifyCallback | undefined): void’, gave the following error. Type ‘(err: VerifyErrors, decoded: string | object) => void’ has no properties in common with type ‘VerifyOptions’.
45 jsonwebtoken.verify(jwt, this.secret, (err: VerifyErrors, decoded: object | string) => { ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
at createTSError (C:\code\js\fullstack_express\express_test\node_modules\ts-node\src\index.ts:434:12)
at reportTSError (C:\code\js\fullstack_express\express_test\node_modules\ts-node\src\index.ts:438:19)
at getOutput (C:\code\js\fullstack_express\express_test\node_modules\ts-node\src\index.ts:578:36)
at Object.compile (C:\code\js\fullstack_express\express_test\node_modules\ts-node\src\index.ts:775:32)
at Module.m._compile (C:\code\js\fullstack_express\express_test\node_modules\ts-node\src\index.ts:858:43)
at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Object.require.extensions.<computed> [as .ts] (C:\code\js\fullstack_express\express_test\node_modules\ts-node\src\index.ts:861:12)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)`
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
those are equivalent
Yep, that fixed it. I was only slightly off on the signature too 😃. You did “decoded? object” and I had “decoded: object | undefined”. Would my type have worked?