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

129
Vistas
Spread array into new array of another type

I've an array of Files (from an input file type) and want to concat them in another array with a different type, but with a File property.

The File array

const files:File[];

The final array type:

export type AttachmentModel = {
    ID?: number;
    Title?: string;
    ServerRelativeUrl?: string;
    File?: File;
}

const attachments:AttachmentModel[];

I've tried to use the spread syntax to merge them, but of course the types are different, so this doesn't work:

const merged = [...attachments, ...files]

If it was only a single object I would have done like this:

var testFile: File;
var testeAttachment: AttachmentModel = { ...{ ...testFile, File: testFile } };

How can I use "destructuring" in the files array so it returns an array of type AttachmentModel?

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

0

It looks like you want to end up with a array of AttachmentModel. If so, you'll want to map your File object to AttachmentModel objects:

const merged: AttachmentModel[] = [
    ...attachments,
    ...files.map((file) => ({File: file}))
];

Playground link

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