From f0e4f30280706f8030df469c90c692aea356e58f Mon Sep 17 00:00:00 2001 From: timechainz <126361786+timechainz@users.noreply.github.com> Date: Fri, 5 May 2023 08:09:49 -0400 Subject: [PATCH] Update TokenInterface for strict typescript Optional members on TokenInterface breaks strict typescript compliance. Modify Json type to support undefined and explicitly override the optional properties to support undefined type. --- src/decode.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/decode.ts b/src/decode.ts index 506782f..10254cb 100644 --- a/src/decode.ts +++ b/src/decode.ts @@ -3,22 +3,22 @@ import * as base64url from './base64Url'; export interface TokenInterface { header: { [key: string]: Json; - alg?: string; - typ?: string; + alg: string | undefined; + typ: string | undefined; }; payload: | { [key: string]: Json; - iss?: string; - jti?: string; - iat?: string | number; - exp?: string | number; + iss: string | undefined; + jti: string | undefined; + iat: string | number | undefined; + exp: string | number | undefined; } | string; signature: string; } -export type Json = string | number | boolean | null | { [property: string]: Json } | Json[]; +export type Json = string | number | boolean | null | undefined | { [property: string]: Json } | Json[]; export function decodeToken(token: string | TokenInterface): TokenInterface { if (typeof token === 'string') {