TypeScript: Interfaces vs Types - Learn in 5 minutes

preview_player
Показать описание
What are the differences between Interfaces and Types in the TypeScript language? Here is a quick overview of the two concepts and their key differences. In this 5 minutes review you will see real examples of the use of interfaces and types.

00:00 Intro
00:24 What are Types?
01:08 What are Interfaces?
02:19 Difference Interfaces vs Types.
03:47 When to use them.
04:23 Conclusion

#typescript #programming #frontend #javascript
Рекомендации по теме
Комментарии
Автор

One key observation to know the difference between types and interface is the operations you can run on types. So, the idea is that types are use, to dynamically work with declaring types and to deep manipulation of types. Intefaces are use in the classic way of declaring type (static type), this decouples interface definition from managing types dynamically. So, they create types. The difference used is clear, you should use types to dynamically create types and when you want to deeply change something. For instance, a range of numbers between 10 and 30. Or the union of two types. This decoupling between concepts also allows you to speak in any other programming language about interfaces without mixing the functionalities of types with it.

titusfx
Автор

Thanks for the explanation! Typescript seems to be very cool and helpful, it makes your code cleaner! But at the beginning it seems so complicated as well.

julianojika
Автор

Your comment about interfaces as defining contracts in the code is an interesting one.

arnthorsnaer
Автор

cool stuff mate
really simplifies understanding when to use what thanks

surajnukala
Автор

Is it okay to use types for making fetch calls or laying out the api model and interface for component properties? Still learning, but I hope I'm asking this properly.

andrewnleon
Автор

thanks man, i am starting typescript and its bit scary but very useful :)

mastercode