const datas = {
a: {
"0": 0,
"1": 1
},
b: {
"0": 0
}
}
function fetchValue (data:keyof typeof datas, prop: "0"|"1") {
if(prop in datas[data]) {
return datas[data][prop] // <- encountering error on this line
}
}
Encountering an issue due to 'Property '1' does not exist on type '{ "0": number; "1": number; } | { "0": number; }'.ts(7053)
Despite having an if statement to verify if the property prop
exists in datas[data]
, TypeScript seems to be neglecting it and throwing errors.