type __Awaited = T extends Promise ? U : T will work and no recursivity
@LachlanMiller
7 ай бұрын
Good catch - I've always used the recursive snippet, but it's overkill for what I was demonstrating here.
@studiowebselect
7 ай бұрын
@LachlanMiller by the way, I learn so mush from you. Love your videos! Continue your great work
@LachlanMiller
7 ай бұрын
Thanks@@studiowebselect ! Trying to get back into a habit of posting content. Knowing people find it useful really motivates me!
@user-dw2ce5tb1k
7 ай бұрын
What about nested promises tho. Wont work for those
@LachlanMiller
7 ай бұрын
@@user-dw2ce5tb1k Yeah, depends what you want. The recursive solution handles the nested cases. Here's the actual one from TypeScript: gist.github.com/lmiller1990/067b9d296bf5a3b05151437009ad7235
@JesseBethke
22 күн бұрын
For the Index Types; what I do is define TestingTypes as an enum and TestingType as a `typeof keyof TestingTypes`
@siyedyoussef3202
7 ай бұрын
love this kind of video it open your eyes about some typescript magic keep up the great work
@LachlanMiller
7 ай бұрын
Thank you!
@yassinebenazouz4529
7 ай бұрын
very helpful thank u ^ ^
@malcolmvernon6808
Ай бұрын
typescript already gives you warnings if you try to edit a const array or object litteral
@LachlanMiller
Ай бұрын
Did not realize this - which tip are you referring to w/ this comment specifically?
@malcolmvernon6808
Ай бұрын
@@LachlanMiller In close to the beginning of the video you said to mark const variables "as const" in typescript (first tip actually). And I thought "wow what a cool trick" and then I did an experiment with it and then I was like - WAIT A MIN - typescript already does this out the box without needing to add as const to it. I'm not sure if maybe older typscript versions didn't do that. I tried it mutating both const array and const object litterals and it all gives red warning underlines for it out the box with my tsx files if you try to mutate them
@LachlanMiller
Ай бұрын
@@malcolmvernon6808 I think older versions of TS did not do this, glad it's getting stricter
@user-ug8qc6tr6b
6 ай бұрын
Great content! keep going
@LachlanMiller
6 ай бұрын
Thank you, will do s🫡
@EdwinMartin
7 ай бұрын
“It isn’t a true constant variable, like it is in other languages” That not true. In C++, Java (final), C# (sealed) and probably others, it works just like JavaScript.
@LachlanMiller
7 ай бұрын
My bad, I don't know enough other languages. I guess what I meant was I expect keyword claled "const" to be immutable and, well, constant! Thanks for pointing this out.
@snatvb
7 ай бұрын
2:17 - it's tuples
@LachlanMiller
7 ай бұрын
It's called a tuple? I thought a tuple was something different, like `type T = [number, string]`. Is this really the same type?
@snatvb
7 ай бұрын
@@LachlanMiller ahhh, maybe I understand you wrong when you use "as const" for array you will get tuple (really strict, with literals in your case), as I get you mean foo[number] - this way to get something from foo it's part of cycles in typescript (keyof works same inside ts) you can use foo[string] as well, or template strings inside recursive types to filter something
Пікірлер: 22