What is the purpose of the public access modifier for classes in Typescript?
What is the difference between
export class Thing {
public doStuff(){
It's just an explicit way to set the method to be public
. By default all class methods / properties in TypeScript are of type public, but you can as well note this in your code for clarity.
You can read more about it in the Handbook, here is an excerpt :
Public by default
In our examples, we’ve been able to freely access the members that we declared throughout our programs. If you’re familiar with classes in other languages, you may have noticed in the above examples we haven’t had to use the word public to accomplish this; for instance, C# requires that each member be explicitly labeled public to be visible. In TypeScript, each member is public by default.
You may still mark a member public explicitly.