I’m working with an API that returns an object, and somehow this object has properties that are both set and undefined
at the same time. How is this possible?
The code in question:
apiClientConnectionObject?.getState().then((state) => {
//Comment 1: state = JSON.parse(JSON.stringify(state))
//Comment 2: state = {name: "n", <...>}
console.log(state)
document.body.append(
`${state.name}n${state.name === undefined}n${JSON.stringify(state)}n`
)
})
and this produces the following output:
undefined true {"state":{<...>, "name":"Available", <...>}}
(JSON is trimmed here, but I have validated it with third party tools) and name is defined as:
name: string;
Note the two comments. Comment 1 produces the same output, but comment 2 does work. This leads me to believe that nothing is wrong with my print statement, but something is off about the object itself, but I don’t know what. I’ve been unable to reproduce the problem outside of this one, very specific, API call.