From 0839aa55e173289788f3cc83a1cb523c630a8d7b Mon Sep 17 00:00:00 2001 From: Casey Chow Date: Mon, 6 Apr 2020 19:24:10 -0700 Subject: [PATCH] [jsonwebtoken make callbacks nullable (#43686) * make callbacks nullable * fix aux tests --- types/jsonwebtoken/index.d.ts | 6 +++--- types/jsonwebtoken/jsonwebtoken-tests.ts | 9 +++++++-- types/sc-auth/sc-auth-tests.ts | 2 +- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/types/jsonwebtoken/index.d.ts b/types/jsonwebtoken/index.d.ts index a5ab4d6824..0f118d14ec 100644 --- a/types/jsonwebtoken/index.d.ts +++ b/types/jsonwebtoken/index.d.ts @@ -91,12 +91,12 @@ export type VerifyErrors = | NotBeforeError | TokenExpiredError; export type VerifyCallback = ( - err: VerifyErrors, - decoded: object, + err: VerifyErrors | null, + decoded: object | undefined, ) => void; export type SignCallback = ( - err: Error, encoded: string + err: Error | null, encoded: string | undefined ) => void; export interface JwtHeader { diff --git a/types/jsonwebtoken/jsonwebtoken-tests.ts b/types/jsonwebtoken/jsonwebtoken-tests.ts index f1bd32db50..08b8b4671e 100644 --- a/types/jsonwebtoken/jsonwebtoken-tests.ts +++ b/types/jsonwebtoken/jsonwebtoken-tests.ts @@ -46,9 +46,14 @@ token = jwt.sign(testObject, { key: privKey, passphrase: 'keypwd' }, { algorithm // sign asynchronously jwt.sign(testObject, cert, { algorithm: "RS256" }, ( - err: Error, - token: string, + err: Error | null, + token: string | undefined, ) => { + if (err) { + console.log(err); + return; + } + console.log(token); }); diff --git a/types/sc-auth/sc-auth-tests.ts b/types/sc-auth/sc-auth-tests.ts index 4fa57d3391..0e33967108 100644 --- a/types/sc-auth/sc-auth-tests.ts +++ b/types/sc-auth/sc-auth-tests.ts @@ -41,7 +41,7 @@ authEngine.signToken(testObject, secret, { algorithm: "RS256" }); // the algorit // sign asynchronously authEngine.signToken(testObject, cert, { algorithm: "RS256" }, (err, token) => { - signedToken = token; + signedToken = token as string; }); // verify a token symmetric