Day 3 of TypeScript — As a Beginner

Things I’ve learned on day 3…

SriniWhoCodes
2 min readJun 6, 2023
Photo by Chris Ried on Unsplash

Things that I have learned today:

  1. Optional Property
  2. 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, the last 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 __):
Optional Property

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👇
Union Type Code Example
  • 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👇
Zoom In to See What’s in it!

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!💘👋

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

SriniWhoCodes
SriniWhoCodes

Written by SriniWhoCodes

I write about Web Development and other related stuffs.

No responses yet

Write a response