Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWT #16989

Closed
svipas opened this issue Jun 6, 2017 · 4 comments
Closed

JWT #16989

svipas opened this issue Jun 6, 2017 · 4 comments

Comments

@svipas
Copy link
Contributor

svipas commented Jun 6, 2017

I'm using VS Code. It's based on TypeScript, it uses all TS definitions. The problem is with jsonwebtoken library. jwt.sign(...,) doesn't have Object.

// Type definitions for jsonwebtoken 7.2.0
// Project: https://github.com/auth0/node-jsonwebtoken
// Definitions by: Maxime LUCE https://github.com/SomaticIT, Daniel Heim https://github.com/danielheim
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.2

export declare function sign(payload: string | Buffer | object, secretOrPrivateKey: string | Buffer, options: SignOptions, callback: SignCallback): void;

In JWT you can pass any object you want, but simple jwt.sign({userId: 1},...) doesn't work it says:

Argument of type '{ userId: number; }' is not assignable to parameter of type 'string | object | Buffer'.
  Object literal may only specify known properties, and 'userId' does not exist in type 'string | object | Buffer'.
@ghost
Copy link

ghost commented Jun 6, 2017

Should be fixed by microsoft/TypeScript#16290. Please try it out with typescript@next once that's in.

@mdebruijne
Copy link
Contributor

As @andy-ms mentioned, this is due to a bug in TypeScript (microsoft/TypeScript#16235)

The workaround is to use type inference (or casting), for example;

const payload = { "foo": "bar" }

jwt.sign(payload, secret)

@svipas
Copy link
Contributor Author

svipas commented Jun 6, 2017

@mdebruijne Thanks, already did that.

@orta orta closed this as completed Jun 7, 2021
@orta
Copy link
Collaborator

orta commented Jun 7, 2021

Hi thread, we're moving DefinitelyTyped to use GitHub Discussions for conversations the @types modules in DefinitelyTyped.

To help with the transition, we're closing all issues which haven't had activity in the last 6 months, which includes this issue. If you think closing this issue is a mistake, please pop into the TypeScript Community Discord and mention the issue in the definitely-typed channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants