Advent of TypeScript 2023 Solutions
My solutions for advent of typescript 2023 on https://typehero.dev. Will be updating as I go along.
Day 1
type SantasFavoriteCookies = 'ginger-bread' | 'chocolate-chip';
Day 2
type CookieSurveyInput<T extends Object> = keyof T;
Day 3
type GiftWrapper<First, Second, Third> = {
present: First;
from: Second;
to: Third;
}
Day 4
type Address = { address: string; city: string };
type PresentDeliveryList<T extends Object> = {[K in keyof T]: Address};
Day 5
type SantasList<Bad extends readonly unknown[], Good extends readonly unknown[]> =
[...Bad, ...Good]
Day 6
type FilterChildrenBy<T, U> = T extends U ? never : T;
Day 7
type AppendGood<T extends Record<string, unknown>> = {
[K in keyof T & string as `good_${K}`]: T[K];
}
Day 8
type RemoveNaughtyChildren<T extends Object> = {
[K in keyof T as K extends string & `naughty_${string}` ? never: K]: T[K];
};
Day 9
type Reverse<T extends string> = T extends `${infer First}${infer Rest}`
? `${Reverse<Rest>}${First}`
: T;
Day 10
type StreetSuffixTester<T extends string, U extends string> = T extends `${infer Rest}${U}`
? true
: false;
Day 11
type SantaListProtector<T extends Record<string, any>> = {
readonly [K in keyof T]: T[K] extends Function
? T[K]
: T[K] extends Record<any, any>
? SantaListProtector<T[K]>
: T[K]
}
Day 12
type FindSanta<T extends string[]> = T extends [...infer Rest extends string[], infer Last]
? Last extends "๐
๐ผ"
? Rest['length']
: FindSanta<Rest>
: never;