H
Hono3mo 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
hOP3mo ago
It still does work, just that webstorm is complaining. Maybe is this its problem instead of Hono's?
Aditya Mathur
Aditya Mathur3mo 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
hOP2mo ago
still complains idk
No description
Aditya Mathur
Aditya Mathur2mo 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 Mathur2mo ago
No description
h
hOP5w ago
my final solution, just context.get('user' as any)
Aditya Mathur
Aditya Mathur4w ago
Can you show the code snippet?
Want results from more Discord servers?
Add your server