Reputation: 3302
I have two query params from the url and trying to take them out by using {}
and assign types to them. However, it is causing error.
const {firstName: string, lastName: string} = req.query;
I am getting cannot redeclare block-scoped variable 'string'.
. Is it possible to assign type inside the {}
? Or, do I have to assign them one by one?
Upvotes: 0
Views: 274
Reputation: 14269
You can't type your variables inside your destructuring assignment as the :
has a different meaning in objects, you have to type the whole object:
const {firstName, lastName}: {firstName: string, lastName: string} = req.query;
Upvotes: 3