Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
noman-maken opened this issue Apr 9, 2023 · 1 comment

Comments

@noman-maken
Copy link

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?

@fahad987
Copy link

fahad987 commented Apr 11, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants