Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

376
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!