Skip to content

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

@noman-maken

Description

@noman-maken

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions