panaverse/learn-typescript

Why am I seeing console.log output for non-exported object properties in my TypeScript code and how can I prevent this?

noman-maken opened this issue · 1 comments

I have two files, index.ts and app.ts. The index.ts file defines two objects, profile and person. profile is not exported, but it is logged to the console using console.log(profile["age"]) and console.log(profile["education@"]). person is exported as the default export.

In app.ts, I import person using import person from "./index.js"; and log person.name to the console using console.log(person.name);. I compile the TypeScript code using tsc and then run the resulting JavaScript code using node app.js.

index.ts

const profile = {
    name : "Noman..",
    age : 25,
    "education@": "BSSEs",
}

const person = {
    name : "Noman",
    age : 24,
    "education@": "BSSE",
}

console.log(profile["age"]);
console.log(profile["education@"]);

export default person;

app.ts

import person from "./index.js";

console.log(person.name);

The output is

25
BSSEs
Noman

My question is, why am I seeing console.log output for profile properties in my app.js output even though I have not exported the profile object from index.ts? Also, how can I prevent this console output from appearing in my app.js output?