@@ -15,7 +15,7 @@ export type PubkeyResolver = (keyId: string) => PubkeyData | Promise<PubkeyData>
1515export type PrivkeyResolver = ( keyId : string ) => PrivkeyData | Promise < PrivkeyData >
1616
1717// tslint:disable-next-line:max-line-length
18- type JwtVerifyAsync = ( token : string , publicKey : string | Buffer , options ?: jwt . VerifyOptions ) => Promise < object | string >
18+ type JwtVerifyAsync = < T extends string | object > ( token : string , publicKey : string | Buffer , options ?: jwt . VerifyOptions ) => Promise < T >
1919type JwtSignAsync = ( payload : string | Buffer | object , privateKey : { } , options ?: jwt . SignOptions ) => Promise < string >
2020
2121shim ( ) // util.promisify shim
@@ -65,7 +65,7 @@ export class JwtHandler {
6565 * @param {Object } options Validation options (jsonwebtoken module options)
6666 * @return {Promise<Object, JsonWebTokenError> } Promise to the JWT body
6767 */
68- public async verify ( jwtRaw : string , options ?: jwt . VerifyOptions ) : Promise < string | { [ key : string ] : any } > {
68+ public async verify < T extends string | { [ key : string ] : any } > ( jwtRaw : string , options ?: jwt . VerifyOptions ) : Promise < T > {
6969 if ( ! jwtRaw ) {
7070 throw new jwt . JsonWebTokenError ( "Empty JWT" )
7171 }
@@ -77,7 +77,7 @@ export class JwtHandler {
7777 throw new UnknownKeyIdError ( keyId )
7878 }
7979 debug ( "cert found" )
80- return this . jwtVerifyAsync ( jwtRaw , certData . cert , options )
80+ return this . jwtVerifyAsync < T > ( jwtRaw , certData . cert , options )
8181 }
8282 throw new Error ( "No public key resolver specified" )
8383 }
0 commit comments