In my Typescript GraphQL code, I am trying to implement destructuring. However, many of the API functions use data
as the first level key. I'm facing an issue where changing let
to var
results in a request for let
, leading to errors such as
Cannot redeclare block-scoped variable
and block-scoped used before its declaration
. Using const
also throws an error. Removing the second let
prevents me from destructuring the second data
.
let {data}:OverlayEventDetail = await modal.onDidDismiss();
if (data.save) {
if (shop) {
//update
} else {
const input: CreateShopInput = {
name: typeof data.name === 'string' && data.name.length > 0 ? data.name : null,
keywords: []
};
let {data}:{data:CreateBlahMutation} = await API.graphql(graphqlOperation(mutations.createShop, {input}));
}
}
The workaround I am currently using involves both const {data}
and // @ts-ignore
on the name
line.