Hacker News new | ask | show | jobs
by crabmusket 1616 days ago
> We recommend the new #somePrivateField syntax for a straightforward reason: these two features are roughly equivalent.

The author of the article surely knows the significant difference between JS private fields and TS private fields: TS private fields can be easily circumvented, whereas JS private fields cannot. See TS playground link[1]

I think this is a significant enough point that people should not be taught that TS's private is just a different way of doing the same thing. I've always said that TS is basically a fancy linter, and sometimes that's exactly what you want.

TS's private keyword communicates programmer intent, but lets you do what you like when you really have to. Just like the rest of TS.

[1]: https://www.typescriptlang.org/play?#code/MYGwhgzhAECC0G8BQ1...

1 comments

I mean if you look at it like that, then yeah sure anything in TypeScript can ultimately be circumvented. Just like `unsafe` in Rust or `unsafePerformIO` in Haskell.

The point is that we as developers choose to respect the typechecker.

Rust's `unsafe` can't do anything and nor can `unsafePerformIO`. There seems to be no way to break into #private fields, unless I've missed something. So I think the difference is significant.

I'm not saying that TS being a "fancy linter" is a bad thing - I actually think quite the opposite.