Timo Martinson
Timo Martinson11mo ago

Property 'params' does not exist on type 'Context<State, Record<string, any>> ... what to do?

I want to access params in oak, but typescript complains. What can I do about that? Thanks.
2 Replies
Timo Martinson
Timo Martinson11mo ago
this is my controller action:
class CityController {
async createCity(context: Context) {
const { citySlug } = context.params
const key = ['cities', citySlug]
const result = await kv.atomic().check({ key, versionstamp: null }).set(key, value).commit()
}
...
}
class CityController {
async createCity(context: Context) {
const { citySlug } = context.params
const key = ['cities', citySlug]
const result = await kv.atomic().check({ key, versionstamp: null }).set(key, value).commit()
}
...
}
pyrote
pyrote11mo ago
I've fought with this when Oak made major updates. Try importing the RouterContext from oak. change the function to (context: RouterContext<string> ) Also there is a helper for grabbing query params that can help too. Import helpers from oak,
const query_params: Record<string, string> = helpers.getQuery(context, { mergeParams: true });
const query_params: Record<string, string> = helpers.getQuery(context, { mergeParams: true });