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

224
Views
Typescript/Node file automatically detects unexported variable from other file

Similar to this question, variables in one file are implicitly found in other files without being exported.

// fileA.ts
const x = 5;
// fileB.ts
const func = () => {
    console.log(x) // no error here
}

But oddly when I export x in fileA.ts, fileB.ts gives an error:

// fileA.ts
export const x = 5;
// fileB.ts
const func = () => {
    console.log(x) // "cannot find name 'x'"
}

Why does typescript detect an unexported variable?

Here is my current ts.config file, using VSCode Version: 1.60.2

{
    "compilerOptions": {
      "module": "commonjs",
      "esModuleInterop": true,
      "target": "es6",
      "moduleResolution": "node",
      "sourceMap": true,
      "outDir": "dist",
      "forceConsistentCasingInFileNames": true,
      "noFallthroughCasesInSwitch": true,
      "isolatedModules": false,
      "strict": true,
      "noImplicitAny": true,
      "useUnknownInCatchVariables": false
    },
    "lib": ["esnext"]
}
about 4 years ago · Juan Pablo Isaza
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!