I am trying to display all the values in my current redux state but I am getting errors involving the unique symbol type and I am not sure how to resolve it.
Object.keys() says it's returning string[] but keyof typeof state includes unique symbol so .map() doesn't work. I added a .filter() clause but that didn't help.
This works fine when run in javascript but typescript screams and refuses to compile.
Simplified example:
const state = useAppSelector(state => state);
return (
<div>
{Object.keys(state).filter((x: keyof typeof state) => x instanceof String).map((x) =>
<div>
<label>{x}</label>
<div>
{Object.keys(state[x]).filter((y: keyof typeof state[x]) => y instanceof String).map((y) =>
<span>{y}: {JSON.stringify(state[x][y])}</span>
)}
</div>
</div>
)}
</div>
);
How can I correctly type this?
EDIT:
I attempted to use the Omit<> utility type:
Object.keys(state).map((x: Omit<keyof typeof state, symbol>) =>
But this still results in an error when accessing the state via state[x]:
Type 'Omit<"auth" | "developer" | "errors" | "info" | unique symbol, symbol>' cannot be used as an index type. ts(2538)