This is the JSON Object that is stored locally
{
"data": {
"John Doe": {"id":"1234", "username":"johndoe"},
"Sia Xander": {"id":"1235", "username":"siax"}
}
}
This is the TypeScript file that I have and I have created this function but it errors out
import { data } from "../Assets/data.json"
function createData(member: string, id: string, username: string) {
return { member, id, username }
}
interface Rows {
member: string
id: string
username: string
}
const rows: Rows[] = []
Object.keys(data).map(member =>
rows.push(
createData(
member,
data[member]["id"], //error
data[member]["username"] //error
)
)
)
I get the following error
Element implicitly has an 'any' type because expression of type 'string' can't be used to index type "data": {
"John Doe": {"id":string, "username":string},
"Sia Xander": {"id":string, "username":string}
}
}
No index signature with a parameter of type 'string' was found on type
"data": {
"John Doe": {"id": string , "username":string},
"Sia Xander": {"id":string, "username":string}
}
}
How do I tell TypeScript that "John Doe" and "Sia Xander" are strings? Or should I change the way I have made the JSON