@types/jsonwebtoken package and had problems.Definitions by: in index.d.ts) so they can respond.After making the promise he gives me these mistakes. The truth is that I'm not sure if they are the types
TS2322: Type 'unknown' is not assignable to type 'UserProfile'
import {
sign as signToken,
verify as verifyToken
} from 'jsonwebtoken'
const verify = promisify(verifyToken);
let userProfile: UserProfile;
userProfile = await verify(token, this.jwtSecret);
TS2554: Expected 2 arguments, but got 3
import {
sign as signToken,
verify as verifyToken
} from 'jsonwebtoken'
const sign = promisify(signToken);
let token: string;
token = await sign(userInfoForToken, this.jwtSecret, {
expiresIn: Number(this.jwtExpiresIn),
});
There's a few issues here.
verify function callback is non standard in that it will be invoked with either the error or the result in the same argument position. promisify requires the function signature function(err, result).promisify<string, Secret, VerifyOptions, UserProfile>(sign) or something like that.There's a few issues here.
- The
verifyfunction callback is non standard in that it will be invoked with either the error or the result in the same argument position.promisifyrequires the function signaturefunction(err, result).- You would need to use the generic version of promisify which I think in the case of sign with the three parameters is
promisify<string, Secret, VerifyOptions, UserProfile>(sign)or something like that.
I fixed the problem by changing import torequire
I fixed the problem by changing import to require
Doesn't this mean that it would import promisify as an any type, thus ignoring the definitions?
Most helpful comment
I fixed the problem by changing
importtorequire