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

282
Vistas
Property 'size' does not exist on type 'unknown'

In my typescript project, I have a list of files coming from an input, I am trying run through a loop in typescript to check if there is any file exceeds the limit,

const allowSize = 104857600; // 100mb
const files = event.target.files;
const hasInValidFileSize = Array.from(files).filter(
    (item) => allowSize < item.size // Error line
  );

The functionality is working fine, but In console its giving me a build error.
TS2339: Property 'size' does not exist on type 'unknown'.

Please help me to fix

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

0

The event.target is unknown to Typescript, you should assign a type to it. I don't know the proper context of the code but something like this perhaps.

document.querySelector('#test')?.addEventListener('change', function(event) {
    const allowSize = 104857600; // 100mb
    const files = (<HTMLInputElement>event?.target)?.files;
    if (!files) return;
    
    const hasInValidFileSize = Array.from(files).filter(
        (item) => allowSize < item.size // No more error
    );

    return hasInValidFileSize;
})

Notice the

(<HTMLInputElement>event?.target)?.files

Since files is a property of HTMLInputElement we can cast the event.target to this type and then request files on it, ? marks are potential undefined/empty values.

EDIT: It is not clear where your code resides thus Im offering a different style of writing to prevent JSX parsing the type declaration as an HTML element with a missing closing tag.

(event?.target as HTMLInputElement)?.files
about 4 years ago · Juan Pablo Isaza Denunciar

0

I have resolved this issue by just adding (: any)

const files = event.target.files;
const hasInValidFileSize = Array.from(files).filter(
    (item: any) => allowSize < item.size
);
`
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