H
Hono6mo ago
h

Argument type string is not assignable to parameter type keyof E["Variables"]

I'm using Hono with Webstorm and whenever I use .get() or .set() with some key of string, webstorm will always complain such type mismatch. Even the type-safe guard on docs doesn't help. The code: https://github.com/search?q=repo%3Aminhperry%2Fcf-worker-backend%20c.get(&type=code
No description
7 Replies
h
hOP6mo ago
It still does work, just that webstorm is complaining. Maybe is this its problem instead of Hono's?
Aditya Mathur
Aditya Mathur6mo ago
make your context type like this
Context<{
Variables: {
user: unknown // Add whatever type you want
}
}>
Context<{
Variables: {
user: unknown // Add whatever type you want
}
}>
h
hOP5mo ago
still complains idk
No description
Aditya Mathur
Aditya Mathur5mo ago
Seems to be working on VSCode -
export const getUserField = (
context: Context<{ Variables: { user: string } }>
) => {
const user = context.get("user");
};
export const getUserField = (
context: Context<{ Variables: { user: string } }>
) => {
const user = context.get("user");
};
Aditya Mathur
Aditya Mathur5mo ago
No description
h
hOP5mo ago
my final solution, just context.get('user' as any)
Aditya Mathur
Aditya Mathur5mo ago
Can you show the code snippet?

Did you find this page helpful?