@@MarekVaníček-u1n Yeah, depends what you want. The recursive solution handles the nested cases. Here's the actual one from TypeScript: gist.github.com/lmiller1990/067b9d296bf5a3b05151437009ad7235
@@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
“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.
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.
@@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
type __Awaited = T extends Promise ? U : T
will work and no recursivity
Good catch - I've always used the recursive snippet, but it's overkill for what I was demonstrating here.
@LachlanMiller by the way, I learn so mush from you. Love your videos! Continue your great work
Thanks@@studiowebselect ! Trying to get back into a habit of posting content. Knowing people find it useful really motivates me!
What about nested promises tho. Wont work for those
@@MarekVaníček-u1n Yeah, depends what you want. The recursive solution handles the nested cases.
Here's the actual one from TypeScript:
gist.github.com/lmiller1990/067b9d296bf5a3b05151437009ad7235
love this kind of video it open your eyes about some typescript magic keep up the great work
Thank you!
For the Index Types; what I do is define TestingTypes as an enum and TestingType as a `typeof keyof TestingTypes`
Great content! keep going
Thank you, will do s🫡
very helpful thank u ^ ^
typescript already gives you warnings if you try to edit a const array or object litteral
Did not realize this - which tip are you referring to w/ this comment specifically?
@@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
@@malcolmvernon6808 I think older versions of TS did not do this, glad it's getting stricter
“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.
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.
2:17 - it's tuples
It's called a tuple? I thought a tuple was something different, like `type T = [number, string]`. Is this really the same type?
@@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