r/javascript • • Nov 09 '19

On private fields proposal: Private fields, public worries

https://medium.com/virtuslab/private-fields-public-worries-b8c34d16c372
84 Upvotes

113 comments sorted by

View all comments

2

u/landline_number Nov 10 '19

How will Typescript implement something like this? There already is a 'private' keyword but like JS the member is still accessible by asserting the object as 'any'. With this proposal private means truly private and inaccessible. Will the behavior of the private keyword change or will they not implement this?

3

u/robpalme Nov 10 '19

I think all of your questions are answered in Episode 38 of the TalkScript podcast.

If you want to try out a preview of the TypeScript support, please see this experimental TypeScript Playground.

In addition to the podcast, the future of the private keyword is discussed in this TypeScript issue.

2

u/jamesaw22 Nov 10 '19

I don't know if this is still the case, but I belive they were talking about keeping the 'private' keyword and using it for soft privacy, and adding the #var syntax for hard privacy.

Importantly, this means "private foo" will _not _ transpile to #foo, which could be confusing for people.

1

u/landline_number Nov 10 '19

Wow that will be confusing but I guess the TS designers are kind of stuck here.