TS2326: Types of property 'sub' are incompatible. Type 'string' is not assignable to type '() => string'.
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:2
- Comments:7 (1 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like the bug is fixed in the pending next version of TypeScript. Installing
typescript@next
(version3.6.0-dev.20190623
) makes the compilation work. We just need to wait for the next release and build with3.4
for now.No idea 😕 I’m going to open an issue on the TS repo today when I get a chance.