Interfaces and Types in TS
There are two different ways in TypeScript how you can specify the structure of your data
- Interface and Types
- They are very similar, almost everything you can do with the Interface, you can also do with the Type
- In TypeScript is recommending to use Interface over Type alias when it's possible
- Interface describes data structure in a more natural way
- Interface keyword exists only in TypeScript non in vanilla JavaScript. It is helping us to write structured and very explicit code that can help you force classes to have certain features or objects in general to have a specific structure. They allow for optional properties and all optional methods if you add a question mark after the method name
- You can't assign a default value inside the Interface, just the property's name, and type
Loading...
Type Alias
Loading...
Join Our Discord Community Unleash your potential, join a vibrant community of like-minded learners, and let's shape the future of programming together. Click here to join us on Discord.
For Consulting and Mentorship, feel free to contact slavo.io