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

I am being able to access private properties outside the class #7687

Closed
pjlunardelli opened this issue Dec 15, 2023 · 5 comments
Closed

I am being able to access private properties outside the class #7687

pjlunardelli opened this issue Dec 15, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@pjlunardelli
Copy link

What version of Bun is running?

1.0.18+36c316a24

What platform is your computer?

Darwin 23.2.0 arm64 arm

What steps can reproduce the bug?

  1. Create a private property
  2. Access it outside the class

Example
async prepare() {
this.fileSystemHandler = new FileSystemHandler(this.finalDir);
console.log(
"file: classifier.ts:29 || this.fileSystemHandler.handler:",
this.fileSystemHandler.handler.data
);
this.fileSystemHandler.handler = {};
console.log(
"file: classifier.ts:31 || this.fileSystemHandler:",
this.fileSystemHandler.handler
);
}

Log:
file: classifier.ts:29 || this.fileSystemHandler.handler: null
file: classifier.ts:31 || this.fileSystemHandler: {}

What is the expected behavior?

Don't run

What do you see instead?

Code running and showing information it shouldn't

Additional information

I was able to get a private property to work via "#property"

@pjlunardelli pjlunardelli added the bug Something isn't working label Dec 15, 2023
@Didas-git
Copy link
Contributor

I dont see any private properties in the example.
As for testing, i dont see any issues and bun seems to be working as intended
image

@pjlunardelli
Copy link
Author

The image haven't been uploaded, my mistake.

Is does work with "#", but it doesn't with private

private handler: StringHandler | BufferHandler;
private helpers: Helpers = { directory: new Directory(this) };

constructor(
path?: string,
mode: Mode = "Buffer",
acceptDir: boolean = false
) {
super(path);
this.mode = mode;
this.handler = new handlermode;
if (acceptDir !== undefined) this.acceptDir = acceptDir;
}

@Didas-git
Copy link
Contributor

private is not a javascript thing.
its a typescript keyword and only works on the type level, it has no effect at runtime

@Jarred-Sumner
Copy link
Collaborator

TypeScript’s private doesn’t use the JavaScript feature for private fields and we cannot change this without breaking lots of code.

@Jarred-Sumner Jarred-Sumner closed this as not planned Won't fix, can't repro, duplicate, stale Dec 15, 2023
@pjlunardelli
Copy link
Author

You are both correct, thanks for the information.
microsoft/TypeScript#31670
https://stackoverflow.com/questions/75480223/compiling-private-to-property

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants