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

378
Vistas
TypeScript doesn't throw errors on later initialized ANY variable

I have a function which only accepts a number variable.

function add(n1: number) {
    return n1 + n1;
}

And I initialize an any variable and assign it a string of '5'

let number1;
number1 = '5';

I was wondering, why doesn't it show an error when I want to pass a string to the function?

console.log(add(number1));

(Of course it outputs 55, because the string is concatenated.)

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

0

If the type is not specified (implicit any) or set to any, the uses of the variable won't be type-checked. This is useful if you gradually migrate JavaScript code to TypeScript.

If you want to flag implicit any's (like the one in your example) as error, use the noImplicitAny compiler flag.

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