Reputation: 2620
I am making a type object in Typescript and getting below error.
Property 'template' of type 'string' is not assignable to string index type '{ data: object; changedProperties: object; }
type Records = {
template: string;
id: string;
[usernmae: string]: {
data: object;
changedProperties: object;
}
}
Please guide me as how to modify the object in order to work fine.
Upvotes: 3
Views: 3206
Reputation:
If you use properties with the same type as your index key, typescript won't be able to tell them apart.
You could, for example, go one level deeper and use the index there:
type Records = {
template: string;
id: string;
usernames: { [usernmae: string]: {
data: object;
changedProperties: object;
}
}
}
Upvotes: 3