Welcome back, for more articulated experience — read the part I first .
Enums ( enum erations ) allow you to group values together with friendlier names. Imagine you had a list of names, here’s how you would structure the
You can grab the values from the enum like so
But wait. It returns the integer which represents the index of the value. Like arrays, enums begin indexing their members starting at
How do we get the value
"Indrek" instead of
Notice how the values are presented as a string.
Another great example would be using enums to store the application states.
In case you’re interested in learning more about
enum — I found a great answer going in the nitty and gritty of
Let’s say we fetched some data from an API. We always expect the data to be fetched — but what if we can’t fetch the data?
Perfect time to return the
never type (special case scenario)
We can call the
error function inside another function (callback)
Notice how we don’t use the
never since inferred return type is
Not very useful on their own.
undefined are subtypes of all other types. That means you can assign
undefined to something like
Type assertions usually happen if you know the type of some entity could be more specific than its current type.
Type assertions have no runtime impact, and is used purely by the compiler. TypeScript assumes that you, the programmer, have performed any special checks that you need.
Here’s a quick demonstration
<> syntax collides with JSX so we use the
as syntax instead.
Now — build something awesome with Typescript! :orange_book:
Thanks for reading, hope you enjoyed and found it useful! Stay awesome!
Indrek Lasn - Medium
Read writing from Indrek Lasn on Medium. Merchant of happiness, founder @ https://vaulty.io, growth/engineering @… medium.com