Created
February 20, 2024 18:01
-
-
Save kraftdorian/607169de3417d26b3ac1aea1f79a2c4c to your computer and use it in GitHub Desktop.
TypeScript utility type to reverse a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Reverse<Input extends string, Acc extends string = ''> = | |
Input extends `${infer Head}${infer Tail}` | |
? Reverse<Tail, `${Head}${Acc}`> | |
: Acc; | |
// const o1: Reverse<'SATOR'> = 'ROTAS'; | |
// const o2: Reverse<'AREPO'> = 'OPERA'; | |
// const o3: Reverse<'TENET'> = 'TENET'; | |
// const o4: Reverse<'OPERA'> = 'AREPO'; | |
// const o5: Reverse<'ROTAS'> = 'SATOR'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment