question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TS2326: Types of property 'sub' are incompatible. Type 'string' is not assignable to type '() => string'.

See original GitHub issue

I don’t know if this is a typings bug, or a library issue.

With the following versions: "@types/jsonwebtoken": "^8.3.0"
"jsonwebtoken": "^8.3.0"

The following snippet:

const jsonWebToken = jwt.sign({
            user_id, // The userID
            sub: 'some-sub', // The id from above
            ulimit: 2 // The usage limit
        }, 'shh');

throws the error:

TS2326: Types of property 'sub' are incompatible.
  Type 'string' is not assignable to type '() => string'.

But if I look at the typings:

export function sign(
    payload: string | Buffer | object,
    secretOrPrivateKey: Secret,
    options?: SignOptions,
): string;

It looks correct?

Workaround:

const jsonWebToken = jwt.sign({
            user_id, // The userID
            sub: 'some-sub', // The id from above
            ulimit: 2 // The usage limit
        } as any, 'shh');

If the sub property indeed needs to be () => string I would happily like to assist with the PR to the typings, but I am not sure what the problem is 🤷🏽‍♂️

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
LoicPoullaincommented, Jun 23, 2019

Looks like the bug is fixed in the pending next version of TypeScript. Installing typescript@next (version 3.6.0-dev.20190623) makes the compilation work. We just need to wait for the next release and build with 3.4 for now.

1reaction
LoicPoullaincommented, Jun 17, 2019

No idea 😕 I’m going to open an issue on the TS repo today when I get a chance.

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Property types are incompatible. Can't get around Type ...
Types of property 'start' are incompatible. Type 'string' is not assignable to type 'Date'. The full code is as follows:
Read more >
Fix CSS variable keys in style attributes in React and Typescript
TS2326 : Types of property 'style' are incompatible. Type '{ "--color": string; }' is not assignable to type 'CSSProperties'. Object literal may only...
Read more >
Type 'string' is not assignable to type in TypeScript | bobbyhadz
The "Type 'string' is not assignable to type" TypeScript error occurs when we try to assign a value of type string to something...
Read more >
Typescript `never` type - Explain Programming
Argument of type 'string[]' is not assignable to parameter of type 'ConcatArray<never>'. Types of property 'slice' are incompatible. Type '(start?: number ...
Read more >
Typescript Type System: How Does it Really Work? Type ...
Error:(59, 8) TS2339:Property 'lessonCount' does not exist on type '{ name: string; }'. And if we check what is the inferred type of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found