VS ์ฝ๋๋ฅผ ์ฌ์ฉํ๊ณ ์์ต๋๋ค. TypeScript๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ํ๋ฉฐ ๋ชจ๋ TS ์ ์๋ฅผ ์ฌ์ฉํฉ๋๋ค. ๋ฌธ์ ๋ jsonwebtoken
๋ผ์ด๋ธ๋ฌ๋ฆฌ์ ์์ต๋๋ค. jwt.sign(...,)
๊ฐ์ฒด๊ฐ ์์ต๋๋ค.
// jsonwebtoken 7.2.0์ ๋ํ ์ ํ ์ ์
// ํ๋ก์ ํธ: https://github.com/auth0/node-jsonwebtoken
// ์ ์: Maxime LUCE https://github.com/SomaticIT , Daniel Heim https://github.com/danielheim
// ์ ์: https://github.com/DefinitelyTyped/DefinitelyTyped
// ํ์
์คํฌ๋ฆฝํธ ๋ฒ์ : 2.2
export declare function sign(payload: string | Buffer | object, secretOrPrivateKey: string | Buffer, options: SignOptions, callback: SignCallback): void;
JWT์์๋ ์ํ๋ ๋ชจ๋ ๊ฐ์ฒด๋ฅผ ์ ๋ฌํ ์ ์์ง๋ง ๊ฐ๋จํ jwt.sign({userId: 1},...)
๋ ์๋ํ์ง ์์ต๋๋ค.
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'.
Microsoft/TypeScript#16290์์ ์์ ํด์ผ ํฉ๋๋ค. typescript@next
์์ผ๋ฉด ์๋ํด ๋ณด์ญ์์ค.
@andy-ms๊ฐ ์ธ๊ธํ๋ฏ์ด ์ด๊ฒ์ TypeScript์ ๋ฒ๊ทธ(Microsoft/TypeScript#16235) ๋๋ฌธ์ ๋๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์๋ฅผ ๋ค์ด ์ ํ ์ ์ถ(๋๋ ์บ์คํ )๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค.
const payload = { "foo": "bar" }
jwt.sign(payload, secret)
@mdebruijne ๊ณ ๋ง์, ์ด๋ฏธ ํด๋์ด.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@andy-ms๊ฐ ์ธ๊ธํ๋ฏ์ด ์ด๊ฒ์ TypeScript์ ๋ฒ๊ทธ(Microsoft/TypeScript#16235) ๋๋ฌธ์ ๋๋ค.
ํด๊ฒฐ ๋ฐฉ๋ฒ์ ์๋ฅผ ๋ค์ด ์ ํ ์ ์ถ(๋๋ ์บ์คํ )๋ฅผ ์ฌ์ฉํ๋ ๊ฒ์ ๋๋ค.