I'm currently tackling an issue with my helper function that updates a form field based on the fieldname. For example, if it's the name field, then form.name will be updated. If it's user[0].name, then the name at index 0 of form.users will be updated. However, I've encountered an error which can be seen in the simplified code snippet below:
const example: Record<string, unknown> = {
'a': 'haha',
'b': [1,2,3],
};
const str = 'b.haha';
const tokens: string[] = str.split(".");
if (typeof example[tokens[0]][Symbol.iterator] === 'function') {
const c = [...example[tokens[0]];
}
I'm struggling to resolve this error: Type 'unknown' must have a 'Symbol.iterator' method that returns an iterator. Thanks