Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

303
Vistas
How to write this list in Typescript? it is currently in Javascript, It is list of cars,

How to write this list in Typescript? I know the code works in TypeScript, but I want the list to have declarative types. it is currently in Javascript, it is list of cars :

const list_of_cars = [{
  type: "Toyota",
  model: "Corolla",
  year: 2009
},
  type: "Ford",
  model: "Mustang",
  year: 1969
}];

I know have tried const car: { type: string, model: string, year: number } =

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Typically, you can define a type or interface for specific objects and specify the individual types for each attribute. You can then define your list as an array of the specific interface or type you defined.

Example:

interface Car {
 type: string
 model: string
 year: number
}

const listOfCars: Car[] = [{
  type: "Toyota",
  model: "Corolla",
  year: 2009
},
  type: "Ford",
  model: "Mustang",
  year: 1969
}];
about 4 years ago · Juan Pablo Isaza Denunciar

0

This is also a valid in typescript. If you want in types then you can write it like this

const list_of_cars:{type:string, model:string,year:number}[] = [{
  type: "Toyota",
  model: "Corolla",
  year: 2009
},{
  type: "Ford",
  model: "Mustang",
  year: 1969
}];

OR you can declare an type and use that

type car={type:string, model:string,year:number}
const list_of_cars : car[] = [{
  type: "Toyota",
  model: "Corolla",
  year: 2009
},{
  type: "Ford",
  model: "Mustang",
  year: 1969
}];
about 4 years ago · Juan Pablo Isaza Denunciar

0

In one of our strictest repos at work we declare explicit types on array containers, which would look like this, if you're interested in seeing it organised professionally:

interface CarType {
    type: string
    model: string
    year: number
}

type CarsType = CarType[]

const list_of_cars: CarsType = [
    { type: 'Toyota', model: 'Corolla', year: 2009 },
    { type: 'Ford', model: 'Mustang', year: 1969 },
]

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda