giritharan
Wed May 08 2024
Generic Classes:
• To ensure that the function correctly infers the type of the argument passed to it and returns the same type, you can use TypeScript's
• If we plan to use generic
• From the above code we can see the example, if we planned to use string we can or boolean we can. The thing is both prop and return type has to be similar
#typescript #javascript
• To ensure that the function correctly infers the type of the argument passed to it and returns the same type, you can use TypeScript's
generic type notation
function identityType<Type>(prop: Type): Type {
return prop;
}
identityType(1);
• If we plan to use generic
<>
have to add, it tells ts compiler as the function in generic fn.• From the above code we can see the example, if we planned to use string we can or boolean we can. The thing is both prop and return type has to be similar
#typescript #javascript