Search code examples
typescriptconstructorprivate-memberspublic-members

Public vs Private in Typescript Constructors


Am I right that public members in a TypeScript constructor are public in the class and that private members are private?

If so, what is the effective difference between public members and properties?

Assuming that the difference is that properties can act more like c# properties (that is, can have code associated with their access) why would you want to make a field public, without the protections inherent in making it a property?


Solution

  • private creates a field and public creates a property.

    This is not like a C# property, in fact what makes it a property is just that it is public. There are no accessors.