The one problem only GENERICS can solve

preview_player
Показать описание
#shorts

Become a TypeScript Wizard with Matt's upcoming TypeScript Course:

Follow Matt on Twitter

Рекомендации по теме
Комментарии
Автор

Just in case anyone is wondering, a generic allows you to use a placeholder for a type in your code, whereas `any` means that the type can be anything, with no restrictions or type checking. Generics provide type safety, whereas `any` disables it.

_tonygaeta
Автор

Awesome. I really enjoy each of the second watching your videos. Thank you so much.

esmaeilmirzaee
Автор

Please make more shorts of various typescript tips. It’s a fast way to learn

WebDevCody
Автор

Great video! Please share with us all your vscode extension thank you 🙌

caiofleury
Автор

Great, where do you put this <T> ? (the placement)

srsajjad
Автор

Just to clarify, here the code infers the return type T. So if we were to write it explicitly, it would have T in two places: the parameter type and the return type. That’s when using generics makes sense – when T is used in more than one place. If T is used in only one place, there’s no point in using the generi

vikingthedude
Автор

I've recently had quite a nice (meaning: taking some time but solvable) challenge to type a generic factory function that returns a sorting function for objects. It accepts either a property key or a selector fn (for nested props). Too much to go into details here, but the end result was so satisfying: I could see how IDE/TS was preventing consumer from using "illegal" object keys.

aram
Автор

This is one of those things I meant that I didn't understand what it says. Thanks for clarifying! (I'm refering to my syntax video suggestion ;-))

Manticore_
Автор

I didn't know how to add generics to anonymous functions before, thanks a bunch

dinaiswatching
Автор

ok first, what extension do you use to show them like that? second, how do you make the subtitle follow whatever you saying?

Fadhilx
Автор

I have a question: This comment showing the result is a VSCode feature or do I need to install which plugin to have something similar?

joaolucasdossantos
Автор

When you finally know the answer to one of these videos, you know you may have spent a bit too much time learning

IgnWombat
Автор

Hegel infers identity function correctly, you should check it out

ІлляМіхневич
Автор

How can I make youtube to give me only such kind of recommendations?

МаксимДраганов-ем
Автор

Is the T a convention or is it a reserved letter?

MobiusCoin
Автор

Why is a generic more suitable than using `any` ?

lordpablo
Автор

Hey Matt, really enjoy your content. Do you have a similar solution for this where you can pass any number of generic arguments to a function and infer their types?

iamchu
Автор

So basically… what generics are essentially about in the first place 😊

dopecello