One interesting feature missing in that description is that you can limit what types a generic type can be using extends; multiple types can be expressed via union.
Definitely a big pro, I think in tomorrow's article I actually use multiple types 🙌.
Generics in general are such a blessing and great way to control types.
Founding Engineer at Isotopes AI, building Aidnn, an AI agent for analytics. Ex-HackerRank. AI engineering, explained simply: youtube.com/@sachin-chaurasiya
I am a Full Stack Developer with more than 5 years of experience. Loves to create complex web applications with a rich user interface and broad set of skills applicable across different domains.
One interesting feature missing in that description is that you can limit what types a generic type can be using
extends; multiple types can be expressed via union.Definitely a big pro, I think in tomorrow's article I actually use multiple types 🙌.
Generics in general are such a blessing and great way to control types.
Java devs will find this feature very familiar :)
In C# the type passed in may be inferred. It that true here?
Generics can be inferred indeed.
If you define them like this for instance, in which case you can pass the inferred type you want.
But in general it will default to the T anyhow. this could just prove to be a security fallback.
This post was really helpful 👍
Thanks MirAli!
Indeed , Typescript generics are life saving.
This is help me to understand
Glad it helped Nazmul 💖
Awesome!
They definitely take some getting used to, and practive.
Oh nice! I'm just learning Typescript and I had no idea of generics. I would have defaulted to using "any".
Thanks for the tip!
Glad it helped!
Generics are so powerful and indeed a valid replacement of any in most cases (when used correctly).
They have way more power than described here, so they can solve a lot of issues 🤯