useRouter query

How do y'all handle typescript with nextjs's query params? Currently I'm doing
const cartId = query.cartId as string;
const cartId = query.cartId as string;
, but I'd rather not use the "as" keyword. query.cartId is of type string | string[] | undefined
1 Reply
cje
cje2y ago
you can write a type guard, but honestly as is fine here
Want results from more Discord servers?
Add your server