Hey everyone, I could really use some help with fixing a typing error related to interfaces. It's been driving me crazy and I'm not sure how to resolve it without using @ts-ignore.
Here is the function causing the issue:
function proceed() {
// @ts-ignore
let mockOptions: MockOptions = {};
Object.keys(models).forEach((modelKey) => {
const _modelKey = modelKey as keyof MockOptions;
const model = models[_modelKey];
// @ts-ignore
if (model.id.includes("not")) {
mockOptions[_modelKey] = false;
} else {
mockOptions[_modelKey] = true;
}
});
emit("proceed", mockOptions);
}
And here is the interface being used:
export interface MockOptions {
hasHotelComment: boolean;
isInStornofrist: boolean;
withDifferentBillingAddress: boolean;
paymentOption: string;
}
What am I trying to accomplish? I am rendering RadioButtons based on the data from my Mock in order to change show case properties. Typically, these properties are booleans but now I want to introduce strings so I can assign values based on the selected Radio button. However, I keep getting an error when adding 'paymentOption: string'. If I switch it back to 'boolean', the error goes away:
TS2322: Type 'boolean' is not assignable to type 'never'.
const _modelKey: keyof MockOptions