D
Deno

help

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

TMTimo Martinson8/21/2023
I want to access params in oak, but typescript complains. What can I do about that? Thanks. 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()
}
...
}
Ppyrote8/21/2023
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 });

Looking for more? Join the community!