Thank you very much Thapa bhai 🙏🏻. Main Afghanistan ka hoo aur Bhagwan ka shukar hai ke mujhe Hindi aata hai. Esee liye mai samajta hoo. Aap ka sekhaane ka tariqha ek damm achcha hai. Aur mai abhi tak aap se bahut saare programming cheeze seekchukaa hoo.
import { log } from "console"; function sum(a:T, b:T): T{ let result : T ; if(typeof a === 'number'){ result = (a as number) + (b as number) as T; }else{ result = (a as string) + (b as string) as T } return result; } log(sum(2,3), sum('Ranjit','Patel'))
I think it is not possible to use these operators using Generics because 'T' represents any data type including objects and arrays which does not support arithmetic operations, does not matter if you specify the generic type while calling the function like add(5,10).
import { log } from "console"; function sum(a:T, b:T): T{ let result : T ; if(typeof a === 'number'){ result = (a as number) + (b as number) as T; }else{ result = (a as string) + (b as string) as T } return result; } log(sum(2,3), sum('Ranjit','Patel'))
I can say that it is one of the best typescript tutorial on TH-cam .thanks a lot thapa bhai 🤗😇
Thank you very much Thapa bhai 🙏🏻. Main Afghanistan ka hoo aur Bhagwan ka shukar hai ke mujhe Hindi aata hai. Esee liye mai samajta hoo. Aap ka sekhaane ka tariqha ek damm achcha hai. Aur mai abhi tak aap se bahut saare programming cheeze seekchukaa hoo.
Nice Video Thapa Bhaiya........................😃
Khatarnak op❤❤😊
amazing work sir
Osm sir 😍
import { log } from "console";
function sum(a:T, b:T): T{
let result : T ;
if(typeof a === 'number'){
result = (a as number) + (b as number) as T;
}else{
result = (a as string) + (b as string) as T
}
return result;
}
log(sum(2,3), sum('Ranjit','Patel'))
This is what I am really looking for which is not even discussed in the video, thanks man.
like your content bro 🤟
Thapa Bhai please suggest what is Difference in between Any & Generics?
sir ye generics k jagah pe hamlog type 'any' he q nhi use krlete
due to type safety and type checking
awsome
*_Plz do a live TH-cam session for Typescript assessment solving live doubt clear ho jayega..._* 🙏
No need of that
@@6.squash.936 jisko jarurt h vo aayege 🙏🏻
ok I will try for sure
@@ThapaTechnical *_Thanks a lot Bhai_* 🙏🏻
♥💙
while adding two numbers i am getting " Operator '+' cannot be applied to types 'T' and 'U'."
I think it is not possible to use these operators using Generics because 'T' represents any data type including objects and arrays which does not support arithmetic operations, does not matter if you specify the generic type while calling the function like add(5,10).
import { log } from "console";
function sum(a:T, b:T): T{
let result : T ;
if(typeof a === 'number'){
result = (a as number) + (b as number) as T;
}else{
result = (a as string) + (b as string) as T
}
return result;
}
log(sum(2,3), sum('Ranjit','Patel'))
sum(a:T, b:U) {
If(typeof a === 'number' && typeof b === 'number')
return a + b;
return a + "" + b;
}
which theme
sum(a:T, b:U) {
If(typeof a === 'number' && typeof b === 'number')
return a + b;
return a + "" + b;
}
😊😊
😍💞💘 𝓣𝓱𝓪𝓷𝓴 𝔂𝓸𝓾 𝓼𝓸 𝓶𝓾𝓬𝓱 𝓼𝓲𝓻. 💔💏💖
Gadha hi krega😂