Practical guides, tutorials, and insights from years of building web and desktop applications. Check out code examples you can actually use!
Public and Private Variables in Typescript
Are public and private variables really public or private? Consider the below example - class MathOp { public x: number; private y: number; } const op = new MathOp(); op.x; // no problem If you try to access the private variable.. op.y; // Error: Property 'y' is private and only accessible within class 'MathOp' What does private even mean? From our earlier definitions, the behaviour seems ok. Or, is it? Just compile the above code block to JS. tsc test1.ts And, the compiled Javascript file is - ...