Skip to content

It allows me to use variables without importing that's declared in other file even but not exported. #55302

Description

@jonasbeckdev

🔎 Search Terms

Typescript version: 5.1.6
I don't get any error even though I use 'port' variable reference in index.ts file without importing it from constants.ts file, even though I didn't use the export keyword when declaring it.

🕗 Version & Regression Information

  • This is a crash
  • This changed between versions ______ and _______
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about _________
  • I was unable to test this on prior versions because _______

⏯ Playground Link

No response

💻 Code

constants.ts
const port = 8000

index.ts

import express from 'express'

const app = express()

app.listen(port, ()=>{

})

tsconfig.json

{
  "compilerOptions": {
    "target": "es2016",                                  /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
    "module": "commonjs",                                /* Specify what module code is generated. */
    "rootDir": "./src",                                  /* Specify the root folder within your source files. */
    "moduleResolution": "node",                       /* Specify how TypeScript looks up a file from a given module specifier. */
    "esModuleInterop": true,                             /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
    "strict": true,                                      /* Enable all strict type-checking options. */
    "skipLibCheck": true                                 /* Skip type checking all .d.ts files. */
  }
}

🙁 Actual behavior

not detecting any error.
tsc build ok. but it's getting a referenceError when running.

🙂 Expected behavior

It should give me an error where I use 'port' variable in index.ts file.
Is it a Typescript bug or am I missing some options in tsconfig file?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions