The structure of my JSON file is as follows:
[
{
"keys": [
{
"date": "2019-06-25T17:33:39.000Z"
}
],
"tag": null
},
{
"keys": [],
"tag": "stringvalue"
}
]
Upon importing the file, Typescript assumes that keys
can be of type any[]
due to the second keys
being an empty array. This results in keys
being interpreted as any[] | IKeys[]
, where IKeys
represents the true shape interface of keys
. Consequently, this restricts the usage of methods like Array.map()
because of incompatible call signatures.
What steps can be taken to ensure that Typescript recognizes the accurate interface of keys
?
For a demonstration, refer to this sandbox example: https://codesandbox.io/s/serene-kare-g7r5r