-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path9.ts
executable file
·14 lines (12 loc) · 1.39 KB
/
9.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
// TS playground link: https://tsplay.dev/advent-of-typescript-2023-9
// Is Santa Dyslexic?
// [it's early Saturday morning and the team has been working overtime. Santa storms into the factory floor shouting..]
// [Santa] Don't you elves take any pride in your work?!?! Others would love to have your job for much less pay! I asked for a simple type that will reverse strings!! How hard is that?!? What do we even pay you for??
// [unfortunately, Santa is conveniently forgetting that the Reverse type was cut from the sprint (which... of course... he agreed to)]
// [floor manager] Ok. We never got acceptance criteria for that ticket.
// [Santa] How difficult is it to understand what Reverse does!? 'rehsaD' should be transformed into 'Dasher', 'recnaD' should be transformed into 'Dancer', 'recnarP' should be transformed into 'Prancer'.. DO I NEED TO KEEP GOING?
// [floor manager] Well you might be surprised. For example, what should happen to multi-codepoint unicode characters?
// [Santa] What are you on about with all that accessibility stuff again!
// [floor manager] Accessibility is important, sir.
// [Santa] Look, this is just an MVP. We can add accessibility later. Just get me my Reverse type! I'm having a hard time reading this stuff otherwise!
type Reverse<T extends string> = T extends `${infer FirstLetter}${infer RestLetters}` ? `${Reverse<RestLetters>}${FirstLetter}` : T