How to define an array of a data type in a property in a JSON object?

0

I have this next obj

nuevoEvento : {
    infoBasica : {
        nombre: String,
        escenario:String,
        valor: [{
            titulo: String,
            valor: String
        }],
        lugar:{
            escenario: String,  
            direccion: String,
            barrio: String,
            ciudad: String,
        },
        genero: String,
        modalidad: String,
        edad: [{
            titulo: String,
            rango: String
        }],
        fechas:{
            inicio: {
                fecha: Date,
                hora: TimeRanges
            },
            limite: {
                fecha: Date,
                hora: TimeRanges
            }
        },
        tipoCompetencia: "Individual" | "Equipos",
    },
    infoAvanzada : {
        cupos: Number,
        inscriptos: String,
        premios: Array<Premio>

    }
}

My concern is more exactly in the prize property, I want to receive only a data type of Prize

export class Premio {
    titulo: String
    valor: String
    constructor(titulo, valor) {
        this.titulo = titulo
        this.valor = valor
    }
}

Is that correct?

    
asked by Daniel Enrique Rodriguez Caste 23.10.2017 в 19:05
source

2 answers

0

If you want it to be an array of type Premio , you should put it:

premios: [Premio]
    
answered by 23.10.2017 в 19:19
0

You can not really define types in Javascript, or at least not from the focus you need. In cases like these, the appropriate option, if you want to continue using Javascript syntax, is to program in TypeScript.

    
answered by 23.10.2017 в 21:32