DEV Community

Discussion on: Type-safe API mocking with Mock Service Worker and TypeScript

Collapse
 
kettanaito profile image
Artem Zakharchenko

Hey!

Query parameters are always either a string or an array of strings. You can provide a narrower type using type casting:

const userId = req.url.searchParams.get('userId') as string
Enter fullscreen mode Exit fullscreen mode