Тёмный

4 ways to use the TypeScript infer keyword 

Andrew Burgess
Подписаться 17 тыс.
Просмотров 12 тыс.
50% 1

I've always been a little baffled by TypeScript's `infer` keyword? So I explored the ways you can use it, and came up with 4 variations! If you have other fun examples of how to use `infer`, let me know in the comments!
0:00 - Intro
0:32 - Generic Arguments
2:25 - Arrays
4:37 - Function Parameters and Return type
7:03 - Template Literals
9:53 - Outro

Наука

Опубликовано:

 

9 июн 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 47   
@stonecoldcold2941
@stonecoldcold2941 Год назад
I've always never understood infer. But the examples you have shown is the best that made me understand finally.
@user-vp7ht2fg1u
@user-vp7ht2fg1u Год назад
That is the best explanation of infer ever. It is not fair. Why shitty stuff like "BECOME A FRONTEND DEVELOPER IN 5 SECONDS" is much more popular...
@vihanv8582
@vihanv8582 2 года назад
Wow! This has got to be the best video on the infer keyword I've ever seen. Keep up the good work Andrew! Liked and subbed 😀
@dimitargetsov9690
@dimitargetsov9690 Год назад
Two reasons to remember and share this channel with anybody: 1.content (on TS) second to none. 2.family name -Burgess--same as of Antony Burgess--"Clockwork Orange".
@andrew-burgess
@andrew-burgess Год назад
Lol thanks!
@serglohm
@serglohm 2 года назад
Great job! This is definitely the best video about infer on 2022!
@devinorium
@devinorium 9 месяцев назад
Upped the production quality. Looks dope
@the_proletariat
@the_proletariat 6 месяцев назад
This was cool. I didn't know anything about infer. Thanks to your video and challenges, now I know. Keep up the good work!
@i.j.5513
@i.j.5513 Год назад
Really nice demonstrations. Thanks a lot! It really made me understand the infer keyword better!
@AiguretDuren
@AiguretDuren Год назад
This was legitimately fun to code along with. Thank you!
@user-zx8js8do5b
@user-zx8js8do5b 2 года назад
What a great explanation, thank you so much!
@BobbyBob21
@BobbyBob21 Год назад
Thank you. Perfect examples.
@user-pk8dz4qc9b
@user-pk8dz4qc9b Год назад
This was the best explanation for infer. Cheers!
@ffedchik
@ffedchik 2 года назад
Awesome content. Keep up the great work!
@vishwajeetraj11
@vishwajeetraj11 Год назад
This was Epix. Looking out for more.
@joshreynolds4164
@joshreynolds4164 Год назад
Great explanation on this. Infer is so powerful
@mohibwasay5102
@mohibwasay5102 2 года назад
Wow. Awesome. Thanks Andrew.
@johnyepthomi892
@johnyepthomi892 Год назад
Dayum. This is very useful. Thanks for sharing.
@developerfriendly
@developerfriendly Год назад
superb tutorial!
@fluxsiarski
@fluxsiarski 3 дня назад
Amazing!
@gangster4208
@gangster4208 Год назад
Thanks for the video!
@kyuubyemy
@kyuubyemy Год назад
My implementation of FirstParam and SecondParam: type FirstParameter any> = T extends (firstParam: infer A, ...args: any[]) => any ? A: never; type SecondParam any> = T extends (firstParam: any, secondParam: infer A, ...args: any[]) => any ? A: never; Also Jojo is everywhere LMAO
@yujitomita3969
@yujitomita3969 2 года назад
Thank you for this. Agreed with Jimmy this is hard.
@chamir4614
@chamir4614 2 года назад
Great video dude!! Thx you :D
@mikedelcastillo
@mikedelcastillo Год назад
you are a god kind sir, thank you!
@ChesterRivas
@ChesterRivas Год назад
This is good stuff.
@edgarabgaryan8989
@edgarabgaryan8989 2 года назад
awesome!
@samirnayibruza9135
@samirnayibruza9135 8 месяцев назад
You could do something like this instead of using overloads on functions: ```ts interface Item { id: number } interface FindOptions { one: boolean } declare function find(options: Options): Options extends {one: infer FindOne} ? FindOne extends true ? Item: Item[] : never const item = find({one: true}) // Item const items = find({one: false}) // Item[] ``` Edit: After a few minutes I realized that in the above case there is no need because I could just do `Options extends {one: true}` directly but imagine the possibilities 😁
@georgejenkins4167
@georgejenkins4167 Год назад
Subbed!
@shayanpaul3430
@shayanpaul3430 Год назад
I have a question related to testing whether two types are equal or not. The utility type in @type-challenge is as follows : export type Equals = (() => T extends X ? 1 : 2) extends (() => T extends Y ? 1 : 2) ? true : false; Maybe it a very basic or idiotic question but i am unable to understand from where this T type parameter is coming from and what will be its values
@andrew-burgess
@andrew-burgess Год назад
Definitely not a dumb question, TypeScript's syntax here is pretty confusing. My understand is that, by declaring a generic parameter T (that declaration is the part), you're saying that T should be assigned when you call the function. Like this: declare function oneOrTwo(): T extends string ? 1 : 2; const x = oneOrTwo(); // 1 const y = oneOrTwo(); // 2, because T defaults to unknown I found this really in-depth explanation of the whole Equals type, which might be helpful too: stackoverflow.com/questions/68961864/how-does-the-equals-work-in-typescript Thanks for watching!
@MohamedRagab-kp6bp
@MohamedRagab-kp6bp 2 года назад
type MyParameters< T extends (...args: any[]) => any, I extends number > = T extends (...args: infer A) => any ? A[I] : never;
@handsome_man69
@handsome_man69 Год назад
Handsome man
@michaelalls8230
@michaelalls8230 Год назад
Tried to use typescript-challenges but getting an error on the import of the challenges utils. Is there something special that has to be done to get that working?
@andrew-burgess
@andrew-burgess Год назад
Hmm, don’t think so. Can you comment with a link to your playground?
@afuzzybearsyoutubechannel2812
@afuzzybearsyoutubechannel2812 Месяц назад
💚
@samirnayibruza9135
@samirnayibruza9135 8 месяцев назад
🤯🤯🤯🤯🤯
@samislam2746
@samislam2746 Год назад
omg, how do you know all that stuff!
@michaeldimmitt9974
@michaeldimmitt9974 Год назад
lol
@JeanAlesiagain3
@JeanAlesiagain3 2 года назад
Typescript has become very complicated
@alsbahsy
@alsbahsy 2 года назад
this is harder than rocket science
@andrew-burgess
@andrew-burgess 2 года назад
Nah, you got this! Let me know if you have questions, happy to help!
@BHFJohnny
@BHFJohnny Год назад
Nope. Too advanced. Need to back off a bit
@andrew-burgess
@andrew-burgess Год назад
Thanks for checking this out! Here’s one where I explain the details a little finely: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-wON6MCS0NkE.html
@AhmedAli-jx9ie
@AhmedAli-jx9ie 9 месяцев назад
I didn't understand shit
@StuartLoria
@StuartLoria 8 месяцев назад
Weirdd explanation
Далее
Type Narrowing in TypeScript
11:51
Просмотров 7 тыс.
TRY NOT TO LAUGH 😂
00:56
Просмотров 3,1 млн
TypeScript Generics are EASY once you know this
22:21
Просмотров 122 тыс.
TypeScript Wizardry: Recursive Template Literals
14:47
Branded Types give you stronger input validation
9:22
How to use TypeScript Enums and why not to, maybe
12:43
An Option type in TypeScript (inspired by Rust)
12:53
Infer is easier than you think
13:38
Просмотров 84 тыс.
Be Careful With Return Types In TypeScript
12:08
Просмотров 60 тыс.
ВСЕ МОИ ТЕЛЕФОНЫ
14:31
Просмотров 31 тыс.
Nvidia Titan
0:48
Просмотров 159 тыс.
Делаю деньги и кайфую
0:59
Просмотров 57 тыс.