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"]
}