Unable to use jwt-decode with typescript project
See original GitHub issueDescription
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
- npm install --save @types/jwt-decode
- npm install --save jwt-decode
- 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:
- Created 4 years ago
- Comments:12 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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}
Hi @rahulbhooteshwar, here’s an example Typescript project with
jwt-decode
.