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'.
Should be fixed by Microsoft/TypeScript#16290. Please try it out with typescript@next
once that's in.
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)
@mdebruijne Thanks, already did that.
Most helpful comment
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;