Here is a snippet of my code:
let show = {
createTag: false,
updateFeature: false,
createFeatureGroup: false,
deleteFeature: false,
deleteCycle: false,
};
I am retrieving a value from the querystring that I want to compare against the keys in the 'show' object.
The current code works fine, but I would like TypeScript to infer it and avoid the need for casting:
const showDialog = $page.query.get('show') || '';
if (showDialog && showDialog in show) {
// I am looking for a way to eliminate the need for "<keyof typeof show>" cast
show[<keyof typeof show>showDialog] = true;
}
I initially thought that using showDialog in show
inside the 'if' statement would inform TypeScript that showDialog is a key in 'show', but it seems this is not the case.