Reputation: 1831
I am trying to define an object:
errors = {}
Then I want to set some items like:
errors['a'] = 'aaaa';
errors['b'] = 'bbbb';
errors['c'] = 'cccc';
But I get errors saying that property 'a' (or any of the other) are undefined. For solving that I add those items to the initial value:
errors = {
'a': '',
'b': '',
'c': ''
}
I have 2 questions:
Upvotes: 2
Views: 88
Reputation: 15619
What is the type I have to assign to errors?
let errors: { a: string, b: string, c: string }
How can I define an object with dynamic properties?
let errors: Record<string, string>
Upvotes: 2