❤ hope everyone enjoys them! It was super fun writing the prompts but I got to say: there are many many other people involved with making typehero into what it has become in such a short span of time!
"Type instantiation is excessively deep" is my worst enemy when doing fun typescript stuff. I've often mapped types to other types recursively, and since the initial type can be nested objects I do technically need to recurse infinitely, but in practice with concrete types that nest 2-3 layers deep it should still work. I wish TS didn't consider the generic when doing the recursion depth check, just concrete types that come out.
type IsObject = P extends Function? never : P extends object? P: never; type SantaListProtector = { readonly [K in keyof T]: T[K] extends IsObject? SantaListProtector: T[K] }; a spin on the explicit solution but not sure if there's hidden issue with this
i was able to get away with something really short for the day13(still has recursion lol) ```ts type DayCounter< F extends number, L extends number, R extends readonly number[] = [1], > = R["length"] extends L ? R[number] | L : DayCounter; ```
Hey buddy, i saw your advent of typescript series, i am beginer, I got stuck in one of the similar code which uses advent of typescript logics, could you please help me out?
21:50 You can do it without an accumulator like this:
type Reverse =
T extends `${infer First}${infer Rest}` ?
`${Reverse}${First}`
: T;
❤ hope everyone enjoys them! It was super fun writing the prompts but I got to say: there are many many other people involved with making typehero into what it has become in such a short span of time!
14:51 You can exclude symbol from K like this: `good_${K extends Exclude ? K : never}`
13 day can be done with small amount of code
type DayCounter = V extends Array<
infer O
>
? T extends U
? O
: DayCounter
: never;
5:19 love the Primagen reference.
lol, I totally missed that!
This is brilliant. I’d love to watch you do more advent of code challenges in typescript.
I couldn't enjoy more this type of code challenge videos! I would love to see more of this. Maybe not just type only. great video!
Wow, such a nice idea!
"Type instantiation is excessively deep" is my worst enemy when doing fun typescript stuff.
I've often mapped types to other types recursively, and since the initial type can be nested objects I do technically need to recurse infinitely, but in practice with concrete types that nest 2-3 layers deep it should still work. I wish TS didn't consider the generic when doing the recursion depth check, just concrete types that come out.
thanks
I used Exclude for day 6
You can just do T["length"] to get the length of a tuple!
type IsObject = P extends Function? never : P extends object? P: never;
type SantaListProtector = {
readonly [K in keyof T]: T[K] extends IsObject? SantaListProtector: T[K]
};
a spin on the explicit solution but not sure if there's hidden issue with this
i was able to get away with something really short for the day13(still has recursion lol)
```ts
type DayCounter<
F extends number,
L extends number,
R extends readonly number[] = [1],
> = R["length"] extends L
? R[number] | L
: DayCounter;
```
You know you’ve succeeded as a dev, when you refer to your own blog posts for info hahaha
This was exactly what I thought to haha
Hey buddy, i saw your advent of typescript series, i am beginer, I got stuck in one of the similar code which uses advent of typescript logics, could you please help me out?
for day 10 you can write "string" instead of "infer _" - I think it makes more sense
Real vim pros map capslock to the escape key.
Yeah, that's good too. I map capslock to control.