hughsk / flat

:steam_locomotive: Flatten/unflatten nested Javascript objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[React Native > Android]: TypeError: Requested keys of a value that is not an object.

joncursi opened this issue · comments

const test = flatten(12345);
console.log(test);

On React Native > iOS, this returns {}. But on React Native > Android, this errors with:

TypeError: Requested keys of a value that is not an object.

@joncursi Why would you even want to flatten a number in the first place?

@King-kay I am flattening a payload from an API. I cannot determine the structure of that payload ahead of time., so sometimes it is a number instead of an object.

@joncursi Oh okay. Is the issue the incoherent behavior of Flat in React Native?
Because Ideally, calling Object.keys (which is used by flat internally) on a number should return an empty array which would explain the empty object in React Native > IOS. Are you absolutely sure the same is not the case for android?

Closing this issue due to lack of response from the author. Also this looks to be an implementation detail of React Native that has probably been ironed out since.