#19: Generics in Typescript 🚀 Make everything Reusable like JAVA & C# | Most Important Topic in TS

Поделиться
HTML-код
  • Опубликовано: 28 окт 2024

Комментарии • 34

  • @ThapaTechnical
    @ThapaTechnical  Год назад

    🚀 For Source Code & Home Assignment 👉 thapatechnical.shop/courses/typescript-crash-course

    • @omrout3957
      @omrout3957 Год назад

      Sir I pay for react js source code ₹50 rs but I didn't get source code

  • @DEEPANSHU_NAG
    @DEEPANSHU_NAG Год назад +3

    Assessment:
    function add(a:T,b:T):T ;
    function add(a:T ,b:T):T ;
    function add(a:any,b:any):any {
    return a+b;
    }
    const result1 = add(5,10);
    const result2 = add("Hello ","World!");

  • @israilysqureshi2288
    @israilysqureshi2288 4 дня назад

    #HomeWork
    function add(val1:T,val2:T):T{
    return val1 + val2;
    }
    let result1 = add(24,8)
    let result2 = add('hello','World')
    console.log(result1)
    console.log(result2)

  • @VikramBais-k7v
    @VikramBais-k7v 4 месяца назад

    function add(a:T, b:T):T{
    return a + b as T
    }
    generics does not + so we need to define a subtype of T which extends number here .. thus T is a subtype of number

  • @CHETANRATHOD-eq1bx
    @CHETANRATHOD-eq1bx Год назад +1

    TypeScript doesn't allow the + operator on generic types with a union constraint. To handle addition for generic types that can support the + operator, you can use function overloading.

  • @subhomoypal7982
    @subhomoypal7982 Год назад

    const add = (par1: T, par2: T): T => {
    return par1 + par2;
    };
    const result1 = add(5, 10);
    const result2 = add("Hello", "World");

  • @rajbarnwalofficial
    @rajbarnwalofficial 3 месяца назад

    Hi, what is difference between generics & any.

  • @yash-eb9zu
    @yash-eb9zu Год назад +1

    Bhaiya mern stack application ko azure par host kaise karna uska video please

  • @ishikamalik4183
    @ishikamalik4183 9 месяцев назад

    source is not in your website for type script kindly share link for source code

  • @paraspandri7283
    @paraspandri7283 Год назад

    Thanks sir ❤❤

  • @web-dev.ashishk
    @web-dev.ashishk Год назад

    day-19- your explanation is aswesome like your videos

  • @parasbhardwaj9061
    @parasbhardwaj9061 6 месяцев назад

    function add(a: T, b: T): T {
    if (typeof a === 'number' && typeof b === 'number') {
    return a + b as T; // Use 'as T' to assert the return type
    } else if (typeof a === 'string' && typeof b === 'string') {
    return (a + b) as T; // Use 'as T' to assert the return type
    } else {
    throw new Error('Unsupported types for addition');
    }
    }
    const result1 = add(5, 10);
    const result2 = add("Hello", "world!");

  • @richasharma7468
    @richasharma7468 5 месяцев назад

    where can i find source code

  • @kuldeepsinghrathore2327
    @kuldeepsinghrathore2327 Год назад

    It gives me error can any to know how to solve it
    function addFun(a:T, b:T):T{
    return a+b
    }
    console.log(addFun(45, 62))
    error:Operator '+' cannot be applied to types 'T' and 'T'.

    • @akashkaushik8684
      @akashkaushik8684 8 месяцев назад

      bro i got same error, have you solved ??

  • @subhomoypal7982
    @subhomoypal7982 Год назад

    Sir It's gives an error how can I take multiple parameters using generics.

    • @kuldeepsinghrathore2327
      @kuldeepsinghrathore2327 Год назад

      yes same here it give me error , here is my code
      function addFun(a:T, b:T):T{
      return a+b
      }
      console.log(addFun(45, 62))
      error:Operator '+' cannot be applied to types 'T' and 'T'.

  • @omrout3957
    @omrout3957 Год назад

    Sir I pay for source code ₹50 rs but I didn't get source code

  • @Radhe_radhe2929
    @Radhe_radhe2929 Год назад

    Op ❤❤😊

  • @ayush_code9849
    @ayush_code9849 Год назад

    🔥

  • @satyam_code
    @satyam_code 2 месяца назад +1

    💚💜🧡

  • @shivamsoni7974
    @shivamsoni7974 Год назад

    1 doubt session lelo Thapa Bhaiya Bahut doubt aa rahe hai mujhe

  • @soumyaprakash1526
    @soumyaprakash1526 9 месяцев назад +1

    Only one example is not enough. It’s a single example. It won’t work

    • @shamsundar1675
      @shamsundar1675 9 месяцев назад

      Exactly, I also had to watch out other youtuber's videos to understand it properly.

  • @shamsundar1675
    @shamsundar1675 9 месяцев назад +2

    I would says its not a detailed explaination. It looks like you just wanna create this video just for the sake of quantity not quality.

  • @rishiraj2548
    @rishiraj2548 Год назад

    👍🙏

  • @ppp5921
    @ppp5921 7 месяцев назад

    your vdo hide many code !
    that not gd to see

  • @manjjj1665
    @manjjj1665 Год назад

    First visit

  • @shiekhpalace2401
    @shiekhpalace2401 Год назад

    Unsubscribed because of picture in thumbnail 😐

  • @jagdishjena9058
    @jagdishjena9058 Год назад

    ᴛʜᴀɴᴋ ʏᴏᴜ ꜱᴏ ᴍᴜᴄʜ ꜱɪʀ.