I need help with representing a JSON object in an Angular2 typescript class. The JSON object contains an array of objects of its own type. Here is what the JSON object looks like:
{
"data": {
"id": 5,
"type": "taxons",
"attributes": {
name: "Vehicles & Vehicle Accessories",
"taxons": [{
"id": 8,
"type": "taxons",
"attributes": {
name: "Make",
"taxons": []
},
"id": 9,
"type": "taxons",
"attributes": {
name: "Model",
"taxons": []
}
}]
}
}
As I create the taxon
model in typescript, I am struggling to represent the self-referencing taxon
in the taxons
array. Currently, my class structure looks like this:
export class Taxon {
constructor (
public id: number,
public name: string,
public taxons: //I am stuck here.
)
}
I am looking for how to reference the self
in order to achieve something like this:
public taxons: Array<self>
Alternatively, any other suggestions on achieving the desired functionality would be greatly appreciated.