Issue
I need to implement an object of type on ts:
{
"validElements": {
"classNames": [],
...: []
},
"invalidElements": {
"classNames": [],
...: []
}
}
My code and error:
interface outputObject {
"validElements": {
"classNames": Array
},
"invalidElements": {
"classNames": Array
}
}
The universal type "Array" requires the following number of type arguments: 1.
But the bigger question here is how do I then use such an interface to add and remove values from it. In fact, I have an eventlistener where I validate the fields and, depending on the value, add a class to one or another array, and then return the object
Also, I will need to add values and delete from arrays that are inside the object. I tried to do it through the interface, but I get the error that arguments are required. How to do it more correctly?
Solution
create an object and specific your type to that object and also change your type from Array
to Array<string>
as per the first answer.
const outputObject: OutputObject = {
"validElements": {
"classNames": []
},
"invalidElements": {
"classNames": []
}
}
Answered By - unpolygon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.