Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 610
Jesse Liberty Avatar asked Oct 18 '25 10:10

Jesse Liberty


1 Answers

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.

like image 64
Jesse Liberty Avatar answered Oct 21 '25 00:10

Jesse Liberty