TypeScript #13: Create Custom Types in TypeScript | Uses with Example

preview_player
Показать описание
So sometimes we have few function arguments like we can see in this method which are going to be used very frequently like the first argument of union type or they could be a complex objects like the second argument which is a person having different properties as firstname and sid Which makes it cluttered and a bit confusing at the function declaration. Also this type might be required in many function declarations which are using this person object.
So to make it simpler in typescript we can create our own custom types which will need to create an alias for your custom type to be defined at just one place and we can reuse that alias directly at all different places.
Рекомендации по теме
Комментарии
Автор

Please explain the scenario where an typescript Interface will be preferred over typescript type or vice versa for objects declarations.

vishalgupta-ebqe