I have an interface in typescript to describe the data type of a structure. The problem is that when accessing this structure within an if, it gives me a typescript error that I don't understand and can't resolve. The code works.
This is the interface
interface ISignUpFormData {
username: {
value: string;
valid: boolean;
unique: boolean;
};
email: { value: string; valid: boolean; unique: boolean };
password: { value: string; valid: boolean };
birthdate: { value: string; valid: boolean };
}
And so I access the data
for (let data in formData) {
if (
formData[data].value === "" ||
!formData[data].valid ||
!formData[data].unique
) {
canContinue = false;
errors.push(data);
}
}
In the if condition lines I get this error:
The element implicitly has type "any" because the expression of type "string" cannot be used to index the type "ISignUpFormData".
No index signature with a parameter of type "string" was found on type "ISignUpFormData".