question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use jwt-decode with typescript project

See original GitHub issue

Description

I am trying to use jwt-decode in a typescript project i.e. Stencil Project & it is throwing following error:

import * as jwt_decode from 'jwt-decode';
.
.
.
let token = "........";
let decoded = jwt_decode(token);

This expression is not callable.Type ‘{ default: <TTokenDto>(token: string, options?: Options) => TTokenDto; }’ has no call signatures.

Reproduction

  • install jwt-decode in any typescript project
  • import it in your code & use
import * as jwt_decode from 'jwt-decode';
.
.
.
let token = "........";
let decoded = jwt_decode(token);
  • build project

Please provide the following:

  • Version of this library used: ^2.2.0
  • Version of the platform or framework used, if applicable: stencil - ^1.3.3 , typescript - 3.7.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (1 by maintainers)

github_iconTop GitHub Comments

8reactions
fabramosdevcommented, Feb 21, 2021

I resolved this issue as follows:

import jwt_decode, { JwtPayload } from 'jwt-decode'; const decoded = jwt_decode<JwtPayload>(token || '') || null;

console.log(decoded); // {id: “601872b3eee5d0001c1cdcb2”, iat: 1613648982, exp: 1613735382}

8reactions
Widcketcommented, Jan 15, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

Typescript error with accessing jwt-decode object
I have installed @types/jwt-decode and I'm having trouble getting this to work.
Read more >
jwt-decode-typescript - CodeSandbox
jwt-decode -typescript ... Using jwt-decode in a Typescript project. ... Activating extension 'vscode.typescript-language-features' failed: Could not find ...
Read more >
jwt-decode - npm
Start using jwt-decode in your project by running `npm i jwt-decode`. ... TypeScript icon, indicating that this package has built-in type ...
Read more >
Implementing a JWT auth system with TypeScript and Node
JSON Web Tokens, commonly abbreviated JWT, are a method for storing a user's session data in a hashed string and using it for...
Read more >
Jwt-decode typescript-在PTT/MOBILE01上汽車保養配件評價分析 ...
2022Jwt-decode typescript討論推薦,在PTT/MOBILE01汽車相關資訊,找jwt decode,Jwt decode ... Unable to use jwt-decode with typescript project #82 - GitHub.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found