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

146
Views
Use Global Variable In Same File As It's Declared?

Is it possible to use a global variable in the same file that it is declared?

The following code does not throw a compiletime error:

declare global {
  const something = "something goes here";
}
export default {
  somethingElse: something + " else"
}

However, it seems to be causing an 'undefined variable' error in the same file and every other file I use it in.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

TypeScript's declare syntax is used to declare variables that already exist globally in the context of a module. For instance, in a web application where variables might be coming from <script> tags that TypeScript isn't aware of, said variables and their types can be declared so that their use can be type checked.

Therefore, TypeScript wouldn't warn you about something being undefined, as it expects the variable to already have been declared elsewhere, and your declare global {} block to be informing it of said declaration.

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!