Day 3 of TypeScript — As a Beginner
Things I’ve learned on day 3…
2 min readJun 6, 2023
Things that I have learned today:
- Optional Property
- Union Types
1. Optional Property
- Optional Property can be used for properties that are not 100% required.
- For example, take first and last names. A
first name
is required. However, thelast name
is not required, right? Except for certain situations. - This Optional Property can be used by using
?
After the variable name. - Here’s the code for that (__without explanation __):

2. Union Type
- You can think of this as a possible parameter.
- For example, let’s say you want to get an input from the user which can be either a string or a number. And you can code based on your needs. Like this👇

- Make sure to use the conditional statement for this because TS might throw an error if your code is working only for one type and not the other. Like this👇

That’s a wrap🚀
I think you find this small blog on TypeScript helpful.
If you did then consider following me and clap this article and comment down below if you’re having any doubts or opinions on this article.
I’ll see you tomorrow with other useful blog.
Thanks and have great day!💘👋