Typescript classes: Is explicit ‘public’ modifier a best-practice?

This is a strongly subjective topic to which no perfect answer exists, IMO. However, I’d say a strong factor in settling on an answer is whether you are using other languages in parallel, and if there is a difference in default accessor modifiers between TypeScript and those other languages.

Take C#, for example. In C#, every property and field without an explicit access modifier is private. In TypeScript it’s public, obviously.

If you happen to be using C# and TypeScript in the same project, or just in parallel, I would recommend going with explicit access modifiers, just for the sake of clarity.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)