I have an error message:
Type 'null' is not assignable to type 'string'.
I found a solution here but I didn't understand the answers for my problem.
My code is presented like this:
const expectedRole = route.data['expectedRole'];
const token = localStorage.getItem('token');
const { userName, roleId } = decode(token);
console.log(roleId);
Edit 2022-02-02
decode method
export class InvalidTokenError extends Error {}
export interface JwtDecodeOptions {
header?: boolean;
}
export interface JwtHeader {
type?: string;
alg?: string;
}
export interface JwtPayload {
iss?: string;
sub?: string;
aud?: string[] | string;
exp?: number;
nbf?: number;
iat?: number;
jti?: string;
}
export default function jwtDecode<T = unknown>(
token: string,
options?: JwtDecodeOptions
): T;
FYI, I copied the code from the project here


