H
Hono8mo 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
hOP8mo ago
It still does work, just that webstorm is complaining. Maybe is this its problem instead of Hono's?
Aditya Mathur
Aditya Mathur8mo 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
hOP8mo ago
still complains idk
No description
Aditya Mathur
Aditya Mathur8mo 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 Mathur8mo ago
No description
h
hOP7mo ago
my final solution, just context.get('user' as any)
Aditya Mathur
Aditya Mathur7mo ago
Can you show the code snippet?

Did you find this page helpful?