'Typing a string index
I have some data.
const people = {
john : {
//somedata
},
peter : {
//somedata
},
mark: {
//somedata
}
}
and I type it
export type People = {
[key : string]: Person
}
export interface Person {
age: number;
profession: string;
// some more data
}
The error is TS7053: Element implicitly has an 'any' type because expression of type 'string' can't be used to index type. I would not usually use a string as the key but in this case it is necessary and typescript does not like it even though I have told it to expect a string.
Any idea how I can type this properly?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
