I have a basic route that implements the following:
router.get('/twitter/tweets', async (ctx) => {
const { limit, page, search } = ctx.query
ctx.body = {
tweets: await twitter.all(limit, page, search),
}
})
The problem I have is with types. The items from ctx.query
return string[] | string
.
The service that it calls is as follows:
async function all(_limit = 50, _page = 0, _search = '') {
Therefore the limit
and page
values are expected to be numbers. What is the best way to handle koa ctx validation in order to pass the correct types to the service.