I am new to typescript.
I have a class Like this
class Document {
constructor (data, id) {
this.data = data
this.id = id
}
}
Here I know that Id is going to be String but data is going to be either object or array.
Can someone help me in figuring out what is going to be the interface for it.
[Update:] What have I tried?
I created an interface like this
interface Documents {
data: Array | Object,
id: Number
}
but this gives following error (red underline below array)
Generic type 'Array' requires 1 type argument(s).
If it makes any difference, I expect my array to be either empty or contain list of objects
constructor (data: object | Array<any>, id: string)?number[],string[]looks more easy for me. Also, when you read them they can be read as "number array" or "string array"