new INFER features in TypeScript 4.8!

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

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

The explanation at 5:41 of how the number literal type parsing works in terms of String(Number()) deserves a gold medal for clarity and brevity 🏅

avi
Автор

Ok, so I have one question after all of this, when will I become a typescript alchemist and be able to apply this sort of thing to real projects 😂

mmmike
Автор

TS has so much depth.
I assumed I had a decent grasp but this is a whole other myriad of subjects.

darkmift
Автор

This is actually really cool.. but sadly this feature to me at least feels like
"Yeah this is really cool, but I can't think of one situation I would need to use it at compile time rather than runtime"

Great explanation!

BlackxesWasTaken
Автор

Good video! I’m sure the few hundred views you’re getting right now will quickly grow, I’ll be back for more :)

jameshamilton
Автор

thanks for the great explanation! made be understand infer better

Xiel
Автор

You can do the nested example with one infer:

type Test<T> = T extends (...args: any[]) => Promise<Array<infer K extends string>> ? K : never;

type T1 = Test<() => Promise<Array<'cat' | 'dog'>>>; // 'cat' | 'dog'

michaelangelojong
Автор

I've been a typescript developer for a while now, and im still not finding use cases for most advanced typescript features. In your video you tried to find a real use case and then used Phone numbers that are enbedded inside types which i can't imagine to happen. Phone numbers would be dynamic data, and i still can't see how i could use those types in any way in combination with that dynamic data.

Would anyone mind to explain this use-case or provide me a real useful example of inferring a part of a string-literal type?

jeremiasnater
Автор

Need to play with this example, cause P3 might axyually start with zero(s) so, given what you said about the parsing process, the return value would be different (0079 would become 79)...

aram
Автор

If input is string in a validation function how would you then construct type X with input string, I don't see point to manually construct type X like that, or I miss something

TheSysmat
Автор

For your 4.7 example, can't you just do:

type OnlyStringReturnType<T> = T extends (...args: any[]) => Promise<Array<infer S extends string>> ? S : never;

It seems to work fine, unless there's some edge cases?

arduano
Автор

I really wanted to be a front end developer until I see all this Typescript syntax, i really enjoyed Javascript

SahraClayton
Автор

ok cool but how to handle this in real life scenarios? I would be grateful for some scenarios/examples

PS-oyxr
Автор

You voice is good but the background music in the way. Assuming it is at max volume of 10, tone it down to say 1 or 2.

gbedumallam
Автор

Music is distracting and very repetitive

ChrisAthanas
Автор

Anyone know why Typescript choose to use ternary operator over the more easily understood if-else alternative?

Ternary overly complicates the type system in my opinion. Since nested ternary is bad practice in regular coding.

gidmanone
Автор

Are u here to show what infer is or what u know about infer? 😂 Why people makes video in youtube i don't know.

dfytq