8 TypeScript Tips To Expand Your Mind (and improve your code)

  Рет қаралды 74,305

Matt Pocock

Matt Pocock

Күн бұрын

00:00 Intro
00:33 ReactNode vs Element
01:26 using for Unit Tests
03:08 Aliasing any to TODO
03:47 Generic functions vs any
04:56 Const Type Parameters
06:11 NoInfer
08:06 (typeof array)[number]
09:09 ElementRef
My PR's to React: github.com/DefinitelyTyped/De...
Become a TypeScript Wizard with my free beginners TypeScript Course:
www.totaltypescript.com/tutor...
Follow Matt on Twitter
/ mattpocockuk
Join the Discord:
mattpocock.com/discord

Пікірлер: 123
@mattpocockuk
@mattpocockuk 3 ай бұрын
The analytics on this video are crazy - most of you are coming from outside KZbin! So, I'd love to know - how did you find this video?
@quangminhtran9968
@quangminhtran9968 3 ай бұрын
an admin share the post to Angular community im verry appreciate it !
@agmmtoo
@agmmtoo 3 ай бұрын
Chrome homepage suggestion.
@jrgenr
@jrgenr 3 ай бұрын
Google app homepage suggestion
@starsonahill5310
@starsonahill5310 3 ай бұрын
Google News
@sleepwiththefishes
@sleepwiththefishes 3 ай бұрын
Shared by a colleague
@ReggieJohnson87
@ReggieJohnson87 3 ай бұрын
Wake up honey, a new utility type just dropped!
@rafael.aloizio1769
@rafael.aloizio1769 3 ай бұрын
There he 1000 times
@fkhan
@fkhan 3 ай бұрын
I woke up
@joaodias1023
@joaodias1023 3 ай бұрын
Hahaha ​@@rafael.aloizio1769o Lá Ele em inglês fica estranho 😂
@rafael.aloizio1769
@rafael.aloizio1769 3 ай бұрын
@@joaodias1023 eu tentei pelo menos kkkkkkkkkkk, e eu nem sei como falar, foi direto do reverso kkkk, se tu souber uma tradução melhor... Lança pra gente hehe
@rahulspoudel
@rahulspoudel 2 ай бұрын
😂😂
@ernestofuentes9333
@ernestofuentes9333 3 ай бұрын
Congratulations for your baby Matt. Now your life is going get another level. Thanks for de video.
@Billiam112
@Billiam112 3 ай бұрын
@5:40, the Scottish(?) accent caught me off guard. 😀
@ScriptCoded
@ScriptCoded 3 ай бұрын
Was just about to go here commenting just that 😄
@theseangle
@theseangle 3 ай бұрын
That's like a whole different person lol
@MartinKapal
@MartinKapal 3 ай бұрын
Was he impersonating someone specific?
@DemanaJaire
@DemanaJaire 3 ай бұрын
You might not know, but Matt has a linguistic channel about English. He hasn't uploaded for years, but I think it's still there.
@SkyyySi
@SkyyySi 3 ай бұрын
Congratulations for your new wizard apprentice 😊 Btw I personally like this format, since having a little more context like this is nice over "single sentence + code.png"
@devdribbles
@devdribbles 3 ай бұрын
100% agree with this! Seeing the NoInfer example helped flesh out the related social media posts I saw earlier.
@Azoraqua
@Azoraqua 3 ай бұрын
Congratulations with the little one!
@DarkStoorM_
@DarkStoorM_ 3 ай бұрын
*New Wizard has joined the game.*
@JuanMoisesTorrijos
@JuanMoisesTorrijos 3 ай бұрын
Congratulations on the baby. Since 90% of my social media consumption is KZbin, it's a good idea to share your knowledge on other SM platforms here.
@RNDev666
@RNDev666 3 ай бұрын
love these videos! its kind of difficult finding the sweet spot with ts content, its usually either very basic or very advanced, but this video really hits it. great job!
@hartmut-a9dt
@hartmut-a9dt 3 ай бұрын
I like that Your videos are short. Very cool & helpful!
@cjcheshire
@cjcheshire 3 ай бұрын
Really cool, very happy for more of these. Especially as you’ve got other priorities to focus on too :)
@Beni9819
@Beni9819 3 ай бұрын
More advanced React/TypeScript channels are so hard to find. This is incredible. Keep it up!
@thisweekinreact
@thisweekinreact 3 ай бұрын
Great tips as always! The using for mocks is going to be so convenient!
@chrisstroud1915
@chrisstroud1915 3 ай бұрын
These were great, I'd definitely love to see more videos like this!
@ronildo
@ronildo 3 ай бұрын
Matt I really like this format by the way and congrats on your baby 🙏
@rojka-_-
@rojka-_- Ай бұрын
Congrats man, best youtuber on typescript.
@Rebel101
@Rebel101 3 ай бұрын
Amazing tips! Thank you Matt!
@lachezarraychev1391
@lachezarraychev1391 3 ай бұрын
Congrats on the baby! Wish you all the best, may the future wizard be healthy and bring you a lot of joy and happiness!
@JustinSBarrett
@JustinSBarrett 3 ай бұрын
Definitely like this format! I'm a relatively new subscriber, and also new to TS, so any little nuggets I can find-even those I might not fully understand now-are most welcome.
@FurryDanOriginal
@FurryDanOriginal 3 ай бұрын
I used to prefer the following, rather than declaring a NoInfer type as it naturally resolves the problem, rather than trying to work around it: declare function createFSM(config: { initial: TDependentState, states: TState[] }): TState; Though, now that NoInfer is officially integrated into the language, I might start using it anyways.
@KekskruemelReloaded
@KekskruemelReloaded 3 ай бұрын
Exactly what I wanted to say as well. In this particular scenario, using NoInfer feels like a smell. But I'm sure there are other, more useful use cases for it.
@sp3ctum
@sp3ctum 3 ай бұрын
For some reason this just clicked for me. Had a bit of trouble understanding the other example in the video.
@sp3ctum
@sp3ctum 3 ай бұрын
Ok I read the beta release notes for this feature. Looks like the justification is that TDependentState is created only to work around this limitation. So I guess it's semantically clearer not to declare a new generic type parameter.
@Caldaron
@Caldaron 3 ай бұрын
love the layouting, you fully vertical on the side, looks great ;-)
@mantovani96
@mantovani96 3 ай бұрын
Love it! I’ve been too busy lately, so I’ve missed some things on other social medias.
@rushikeshg25
@rushikeshg25 3 ай бұрын
Congrats Matt!
@ankitputhran
@ankitputhran 3 ай бұрын
Congratulations Matt !!!
@januszjanus813
@januszjanus813 3 ай бұрын
Horizontal view is dope, kudos 😃
@dr-Jonas-Birch
@dr-Jonas-Birch 3 ай бұрын
andy, thank you. yes i moved it to my advanced typescript playlist
@abbaskareem5281
@abbaskareem5281 3 ай бұрын
last tip is GOAT 🔥Thank you sir
@me_rinta
@me_rinta 3 ай бұрын
Oh wow, didn’t know about `const T` stuff! Thanks for the tip!
@yaiirable
@yaiirable 3 ай бұрын
Reusing content across platforms makes so much sense! Why would you not want to get the most out of the work you are putting in!?
@ronitgurjar5747
@ronitgurjar5747 3 ай бұрын
Ohhhh thanks for this!🔥🔥🔥🔥
@kedardinde
@kedardinde 3 ай бұрын
Congratulations Matt
@p10tube
@p10tube 2 ай бұрын
hello, I definitely want to see more of this :)
@jonathanbeaumont8878
@jonathanbeaumont8878 3 ай бұрын
Congrats!! 🥳
@krome305
@krome305 3 ай бұрын
Congrats Matt! make sure to teach him typescript well :D
@jeromealtariba7339
@jeromealtariba7339 3 ай бұрын
thks a lot for this video. NoInfer is clearly a game changer. what a powerfull utility type !
@markilabot14
@markilabot14 3 ай бұрын
Conngratulations Matt!!!!
@piyushaggarwal5207
@piyushaggarwal5207 3 ай бұрын
ElementRef looks awesome. I will try that.
@abdhelal
@abdhelal 3 ай бұрын
Congratulations 🎉 for little wizard 😊
@rafaveggi
@rafaveggi 3 ай бұрын
Congratulations!!
@biswaranjan6342
@biswaranjan6342 3 ай бұрын
Thanks for this informative video....
@pythagoras281
@pythagoras281 3 ай бұрын
type TODO = any, such an elegant way to increase technical debt 😄
@theseangle
@theseangle 3 ай бұрын
But at least it's easily locatable debt. Almost like an installment plan rather than a debt
@_PCode_
@_PCode_ 3 ай бұрын
Congrats!
@martiananomaly
@martiananomaly 3 ай бұрын
Congratulations on the kid, Matt 🎉
@ColinRichardson
@ColinRichardson 3 ай бұрын
Nice Video.. Yeah, the example I was showing the the other day is pretty much exactly the same as what you had except backwards.. The array was not the source of truth, but the possible initials were.. :D Just with extra steps since I went through the Vue generic component types also :D It was nice to see NoInfer "just working" with it, with no additional complexity.
@diegodoumecq5144
@diegodoumecq5144 3 ай бұрын
Wow, I've had to resort to multiple generics just to solve the inference problem (basically have one generic extend from the other). It worked but I hated that solution and this NoInfer is way more elegant. Bravo!
@atmosph
@atmosph 3 ай бұрын
wish the best luck for the little one! ^^
@JeremyKolassa
@JeremyKolassa 3 ай бұрын
I've always loved your channel, Matt, but I especially love it now that you've had the child. Having the child yourself, and not putting your wife through those nine months, is such a noble sacrifice. We don't see that very often these days. 😜 But seriously, congrats!
@Glinkis
@Glinkis 3 ай бұрын
Obviously he used nine women to get it down to a single month, just like how companies throw developers on a project to get it out faster. Makes perfect sense.
@MichiganTypeScript
@MichiganTypeScript 3 ай бұрын
congrats on the baby!
@DimitarDanailov
@DimitarDanailov 3 ай бұрын
@mattpocockuk thank you very much for the content. Do you think is possible tweets to be added in the description ?
@SR-zi1pw
@SR-zi1pw 3 ай бұрын
Congratulations 🎉
@nofacee94
@nofacee94 3 ай бұрын
You are the best.
@zwanz0r
@zwanz0r 3 ай бұрын
Congrats dad! 🎉
@cn-ml
@cn-ml 3 ай бұрын
I actually didnt know the const type parameters tip. This could have saved me some trouble. I attempted to do this exact thing, but i annotated every function call with doSomething(["hello", "world"] as const) instead of using the parameter.
@vrildox-to7ir
@vrildox-to7ir 3 ай бұрын
Congrats
@Larry21924
@Larry21924 3 ай бұрын
This is sheer brilliance. I had the pleasure of reading something similar, and it was sheer brilliance. "Unlocking the Brain's Full Potential" by Alexander Sterling
@RamonBalthazar
@RamonBalthazar 3 ай бұрын
We're less important than the baby and we understand it! Congrats and good luck with fatherhood!
@deatho0ne587
@deatho0ne587 3 ай бұрын
Like most of these and congrats. Hmm, the type TODO = any; it may be great for library code. But have a doubt in most Prod code it is needed since could just search for any and which should not be in most cases.
@palrevesz8629
@palrevesz8629 3 ай бұрын
Congrats on the baby ;-)
@codeChuck
@codeChuck 3 ай бұрын
Finally, the man lives to his name and is applying the right tools for the job :) Congrats on a child! Well done! :D
@ChimbzZ
@ChimbzZ 3 ай бұрын
Not sure I understand the semantics NoInfer type. Can anyone explain the syntax please?
@AmrouBouaziz
@AmrouBouaziz 3 ай бұрын
The `NoInfer` is so cool! can you explain how the community solution works. It might be interesting to use the same techniques for another situation
@dr-Jonas-Birch
@dr-Jonas-Birch 3 ай бұрын
You create an array with one member and then you index into that array's member which returns the original input value. The computation makes it hard for TS to infer. -dr Jonas Birch, new ts wizard
@AmrouBouaziz
@AmrouBouaziz 3 ай бұрын
@@dr-Jonas-Birch that makes sense! Thanks wizard 🪄
@timmeehan2365
@timmeehan2365 3 ай бұрын
That const generic is fire, I had never heard about it before. Always had to add "as const" in the params to achieve that narrow typing :/
@artyomtaranenko2267
@artyomtaranenko2267 3 ай бұрын
Yesterday I have a problem: why TS (or maybe declare types react) dosen't care about what i pass to useRef for input HTMLInputElement or HTMLDivElement, no any error, but if I try to pass HTMLAnchorElement I got an a error. Someone can explain me, what I do wrong?)
@EvanEdrok
@EvanEdrok 3 ай бұрын
How early do you plan on teaching your new little one coding?? 😊 Congrats 🎉
@dealloc
@dealloc 3 ай бұрын
When moving from JS to TS when TS was almost fresh out the oven, we'd have an alias type called $TSFixMe for 'any'. That way it also didn't conflict with actual TODO comments :P
@adtc
@adtc 3 ай бұрын
That "NoInfer" thing... where was it several days ago when I badly needed it?! Now I don't need it anymore, and I don't even remember where I did... lol Edit: I remember now, it was the props of a component, where TS was inferring T from the wrong prop. It's exactly what it was designed for!
@Learnbynet
@Learnbynet 3 ай бұрын
3:00 i prefer use `type Any = any` this allow me to track all *any in my app and try to fix if ts allow it, sometime no, ts is not perfect.
@AK-vx4dy
@AK-vx4dy 3 ай бұрын
Congratulations to mother, child & father :) Looking at my practice, time will be less and less as kid grow, at least for few years.
@Dude29
@Dude29 3 ай бұрын
Post the link in the description to the PR you opened on the JSX repo
@mattpocockuk
@mattpocockuk 3 ай бұрын
Done!
@Dude29
@Dude29 3 ай бұрын
🙏@@mattpocockuk
@hasankahya589
@hasankahya589 3 ай бұрын
Wow
@libenhailu5193
@libenhailu5193 3 ай бұрын
We want more...
@blizzy78
@blizzy78 3 ай бұрын
can you say "purple burglar alarm"? asking for a friend
@jaydeepkarena
@jaydeepkarena 3 ай бұрын
Are you reading effective TypeScript?
@mattpocockuk
@mattpocockuk 3 ай бұрын
Yes, it's good! New edition coming this year I think.
@edgeeffect
@edgeeffect 3 ай бұрын
I like how you've got a tip to ignore `any` because you should NEVER use `any`.... and then another tip that makes good use of... erm... `any`. ;)
@mattpocockuk
@mattpocockuk 3 ай бұрын
shhhhhh
@poki6041
@poki6041 3 ай бұрын
Alien code XD
@6644guilherme
@6644guilherme 3 ай бұрын
I still cant compreheend infer now theyve made noInfer x.x
@gidmanone
@gidmanone 3 ай бұрын
The Typescript community is slowly but unknowingly creating another (ugly) javascript monster.
@mattpocockuk
@mattpocockuk 3 ай бұрын
That's no way to talk about my child
@gidmanone
@gidmanone 3 ай бұрын
@@mattpocockuk I'm sorry Daddy😃. but I'm sure you agree with me that they building up complexity, solving one problem with another. Looks like we are back in Javascript land (from the other end🥲)
@rikithikatakizu2
@rikithikatakizu2 3 ай бұрын
ComponentProps/ComponentPropsWithoutRef but at the same time ElementRef. Why not ComponentRef??? Agh, React....
@TankorSmash
@TankorSmash 3 ай бұрын
5:41 what in the world
@penewoldahh
@penewoldahh 3 ай бұрын
Have you ever heard of typescript booleanish?
@mattpocockuk
@mattpocockuk 3 ай бұрын
No!
@Killputin777
@Killputin777 3 ай бұрын
you not explaining stuff. only showing
@mattpocockuk
@mattpocockuk 3 ай бұрын
What felt confusing? What left you with questions?
@aramp
@aramp 3 ай бұрын
put your insta in the description Matt
@QwDragon
@QwDragon 3 ай бұрын
Congratulations! I've found this version: type NoInfer = T extends infer U ? U : never; Is it better or worth then type NoInfer = [T][T extends any ? 0 : never]; ? Anyway, ts implemented it as intristic, so I think there were some reasons for that?
@heavierthanlight7173
@heavierthanlight7173 3 ай бұрын
Congrats Matt!
Infer is easier than you think
13:38
Matt Pocock
Рет қаралды 84 М.
Generics: The most intimidating TypeScript feature
18:19
Matt Pocock
Рет қаралды 160 М.
I Need Your Help..
00:33
Stokes Twins
Рет қаралды 11 МЛН
Normal vs Smokers !! 😱😱😱
00:12
Tibo InShape
Рет қаралды 103 МЛН
Glow Stick Secret (part 2) 😱 #shorts
00:33
Mr DegrEE
Рет қаралды 53 МЛН
TypeScript Generics are EASY once you know this
22:21
ByteGrad
Рет қаралды 120 М.
You SHOULD deploy to the edge.
12:06
Ben Holmes
Рет қаралды 52 М.
as const: the most underrated TypeScript feature
5:38
Matt Pocock
Рет қаралды 108 М.
Most TS devs don't understand 'satisfies'
4:10
Matt Pocock
Рет қаралды 51 М.
The Dangers Of Promise.all()
6:15
Theo - t3․gg
Рет қаралды 65 М.
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 940 М.
I Cannot Believe TypeScript Recommends You Do This!
7:45
Web Dev Simplified
Рет қаралды 157 М.
Nokia 3310 versus Red Hot Ball
0:37
PressTube
Рет қаралды 2,3 МЛН
Power up all cell phones.
0:17
JL FUNNY SHORTS
Рет қаралды 45 МЛН
The power button can never be pressed!!
0:57
Maker Y
Рет қаралды 49 МЛН
ПРОБЛЕМА МЕХАНИЧЕСКИХ КЛАВИАТУР!🤬
0:59
Корнеич
Рет қаралды 1,5 МЛН
😱НОУТБУК СОСЕДКИ😱
0:30
OMG DEN
Рет қаралды 1,9 МЛН