1.3: Interfaces
Interfaces let us create a contract that other classes/objects must use. Huh...contracts? Look at it this way. If you are hired to do contract work for an employer, a contract will be created that lays out the work that must be completed in order for you to get paid. So, failure to meet the contract's goals means no money coming your way.
This is the same for TypeScript. Making an interface is explicitly stating what a class/object must have in order to be considered valid. Let's take a closer look:
You probably noticed the question mark after alias
. This indicates an optional property. It does not need to be used.
The advantage to using interfaces is that it allows you to code with intent. This means you have a clear vision on what your code should do, making the planning your app a much easier process. You are not having to play catch-up with the language you are using, you set the plan in motion prior to creation. This also makes it easier for other coders later to hop on the code and know how to work with the classes/objects.
adapted from TypeScript Documentation
NEXT SECTION
Last updated