I have been an angular developer and worked with TS from the past 5 years, still there were a few things to take away from this video. Great work Hitesh
You are doing great Job but please please please complete this Typescript series and provide us all the topics available in Typescript, please do not stop this Typescript series after some videos 🙏🙏
Thanks Hitesh 🙂 I have purchased your Angular course and Vue JS course from LCO and also going to purchase React JS course, I love your teaching style ❤️
Summary: Union type allows a variable to hold one of several specified types. It’s denoted by using the vertical bar (' | ') between types. This is useful when you want to allow multiple types for a single value, while still maintaining some level of type safety. Syntax: let value: string | number;
what if we do this - function getDBId(id: number | string) { // console.log(`db id is ${id}`); if (typeof id === "string") { id.toLowerCase(); } else { id = id.toString(); id += 1; } } when we are converting id to string in the else block it still allows us to add 1 to it in the next loc ideally we should not be able to do that, we can't add number to a string How can we avoid that? Or is it a flaw ?
There are two types of data types we can mention for any variable, either lowercase (number) or uppercase(Number). Mostly we will use lower case one, So why can't we go for upper case?
type User= { username:string; role:string; } type Admin = { role:string; sudo:boolean; } let uncleBob : User | Admin = { username: 'uncle',role:'user',sudo:false} console.log(uncleBob) In this case, instead of User or Admin, it has combined both types of data into one. Is this a problem?
if i have to check using condition then what the need of TS ? if (typeof id === "number") { return id + 10; } else if (typeof id === "string") { return id.toUpperCase(); }
আপনারা যারা একেবারে নতুন শুদু মাত্র তাদের জন্য সহজ ভাবে (graphic design ) সবাই কে ঘুরে আসার দাওয়াত রইল। name: Graphics Robiul. আশা করি অনেক ভালো কিছু শিখতে পারবেন।
Are you aware of new batch of full stack javascript bootcamp ?
hc.lco.dev/jscamp2
I have been an angular developer and worked with TS from the past 5 years, still there were a few things to take away from this video. Great work Hitesh
No one can explain union working with other data objects as perfectly as Hitesh explains in this video.
your TS videos make me powerful day by day☺
You are doing great Job but please please please complete this Typescript series and provide us all the topics available in Typescript, please do not stop this Typescript series after some videos 🙏🙏
Don’t worry, this is not my 1st public playlist. JS is done, golang is done, TS will be done too 😁
Thanks Hitesh 🙂
I have purchased your Angular course and Vue JS course from LCO and also going to purchase React JS course, I love your teaching style ❤️
Another great explanation almost impossible to find somewhere else
Wow this video have so much of knowledge 😍 Learning typescript will pay later
Absolutely
I'm like the video before watching because i know that its good video and helpful
very informative thanks for sharing
Summary:
Union type allows a variable to hold one of several specified types. It’s denoted by using the vertical bar (' | ') between types. This is useful when you want to allow multiple types for a single value, while still maintaining some level of type safety.
Syntax: let value: string | number;
what if we do this -
function getDBId(id: number | string) {
// console.log(`db id is ${id}`);
if (typeof id === "string") {
id.toLowerCase();
} else {
id = id.toString();
id += 1;
}
}
when we are converting id to string in the else block it still allows us to add 1 to it in the next loc
ideally we should not be able to do that, we can't add number to a string
How can we avoid that? Or is it a flaw ?
Thank you sir for providing such a quality content
You are welcome
Good one♥
There are two types of data types we can mention for any variable, either lowercase (number) or uppercase(Number).
Mostly we will use lower case one,
So why can't we go for upper case?
Sir in the last.. I guess we can use Enum Type for strict checking
type User= {
username:string;
role:string;
}
type Admin = {
role:string;
sudo:boolean;
}
let uncleBob : User | Admin = { username: 'uncle',role:'user',sudo:false}
console.log(uncleBob)
In this case, instead of User or Admin, it has combined both types of data into one. Is this a problem?
if i have to check
using condition then what the need of TS ?
if (typeof id === "number") {
return id + 10;
} else if (typeof id === "string") {
return id.toUpperCase();
}
there's no need for else or else if check here because ts is smart enough to infer the only remaining type 'string' for the id variable
Great 👍
Watching it in June 2024 ❤🔥
Lets gooo
Awesome
Thank you sir :)
❤❤❤❤❤❤❤
cool
Day 2
never add 70% are not subscribing video during the the video it breaks the focus
At youtube, call for subscribe is creator’s right. Don’t take such small thing away from creators. ❤️
@@HiteshCodeLabmy point is move it to at the start plz
আপনারা যারা একেবারে নতুন শুদু মাত্র তাদের জন্য সহজ ভাবে (graphic design )
সবাই কে ঘুরে আসার দাওয়াত রইল। name: Graphics Robiul.
আশা করি অনেক ভালো কিছু শিখতে পারবেন।