'type casting desctructured property

I have a nextjs router hook where i am destructuring the following way.

const {
  query: { run_id },
} = useRouter();

the run_id is of following type

run_id: string | string[] | undefined

i would like to type cast as following, but it doesnt work, what am i missing here ?????

const {
  query: { run_id  as string},
} = useRouter();


Solution 1:[1]

You (sadly) have to declare the whole type here.

const {
  query: { run_id },
} : { query: { run_id: string } } = useRouter();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tobias S.