Classes and Access Modifiers
TypeScript classes are JavaScript classes plus types and access modifiers: public (default), private (only inside the class) and protected (the class and its subclasses).
TypeScript classes add types and access control to JavaScript classes. private and protected stop other code from changing internals, and implements checks that a class really fulfils an interface.
Example
implements and abstract classes
Example
You can't create an object from an
abstract class - it's a base that subclasses must finish.Key points
- public, private and protected control access.
- Constructor parameter properties save typing.
- implements checks a class against an interface.
📝 Test yourself
1. Where can a private property be used?
2. What does constructor(public owner: string) do?
3. Fill in the keyword to promise a class follows an interface:
class Express Shipper { }
