Ich verwende VS-Code. Es basiert auf TypeScript, es verwendet alle TS-Definitionen. Das Problem liegt jsonwebtoken
Bibliothek jwt.sign(...,)
hat kein Objekt.
// Typdefinitionen für jsonwebtoken 7.2.0
// Projekt: https://github.com/auth0/node-jsonwebtoken
// Definitionen von: Maxime LUCE https://github.com/SomaticIT , Daniel Heim https://github.com/danielheim
// Definitionen: 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 können Sie jedes gewünschte Objekt übergeben, aber einfaches jwt.sign({userId: 1},...)
funktioniert nicht, es heißt:
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'.
Sollte von Microsoft/TypeScript#16290 behoben werden. Bitte probiere es mit typescript@next
sobald das drin ist.
Wie @andy-ms erwähnt, liegt dies an einem Fehler in TypeScript (Microsoft/TypeScript#16235)
Die Problemumgehung besteht beispielsweise darin, den Typrückschluss (oder das Casting) zu verwenden;
const payload = { "foo": "bar" }
jwt.sign(payload, secret)
@mdebruijne Danke, das habe
Hilfreichster Kommentar
Wie @andy-ms erwähnt, liegt dies an einem Fehler in TypeScript (Microsoft/TypeScript#16235)
Die Problemumgehung besteht beispielsweise darin, den Typrückschluss (oder das Casting) zu verwenden;