Currently, I am developing an application using Typescript and React Native. Within my app, I have a JSON file containing information about poker hands that needs to be accessed.
The structure of the JSON data is as follows:
{
"22": [
[
0,
20
]
],
"32o": [
[
0,
20
]
],
"32s": [
[
0,
20
]
],
"33": [
[
0,
20
]
],
To import the JSON data, I use the following code:
import * as pdata from './push.json';
To access the data, this syntax can be used:
pdata['AA'][0][1]
However, when attempting to access the JSON using dynamically generated keys like so:
currentHand = '32o';
console.log(pdata[currentHand][0][1]);
An error message appears stating "Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '...' No index signature with a parameter of type 'string' was found on type '{ "22": number[][];...'. This issue arises due to the inability to hardcode all possible key options given the large number of keys present in the dataset.
I have been exploring various solutions to resolve this issue but have yet to find one that effectively addresses it.