My current challenge involves typing an object, which seems to be error-free until I try to access a nested property and encounter the dreaded red squiggle.
After some research, I came across suggestions like this:
type FlagValue = string | boolean | number | { [key: string]: FlagValue };
type FlagSet = { [key: string]: FlagValue | FlagSet};
const defaultFlags: FlagSet = {
tracking: false,
banner: {
display: false,
message: "I am the man with no name, Zapp Brannigan!",
},
theme: "dark",
};
The typing of the object works well with this approach, but I face issues when trying to access nested properties.
https://i.stack.imgur.com/EOix2.png
...
Property 'display' does not exist on type 'FlagValue | FlagSet'.
Property 'display' does not exist on type 'string'.
Any insights into what might be missing here?