Union Types - TypeScript Programming Tutorial #3

preview_player
Показать описание
With Union Types in TypeScript, you are able to give options as to what data type a value may be. This includes things such as variables, constants, function parameters and even return values. This is an example of an "advanced" type (according to the documentation) and is useful for making generic functions where sometimes it may not be worth writing an extra function for another type, without losing any annotation integrity ;)

In this video I take you through an example with HTML, changing the background color of some elements through the use of a union type in a function. This function can accept either a single HTMLElement or a string and does different things based on which one it is (narrowing).

Check this out:

Follow me on Twitter @dcode!

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
Рекомендации по теме
Комментарии
Автор

what keyboard is this. Cant stop listening

kiwi
visit shbcf.ru