@cuppachino/type-space
Version:
A collection of type utilities for TypeScript.
13 lines (12 loc) • 442 B
TypeScript
import type { Chars } from './chars';
import type { Join } from '../join';
import type { Reverse } from '../tuples/reverse';
/**
* Reverses a string literal.
*
* @example
* ```ts
* function ReverseString<Str extends string>(str: Str): ReverseString<Str> => str.split('').reverse().join('') as ReverseString<Str>
* ```
*/
export type ReverseString<T extends string> = Join<Reverse<Chars<T>>> extends infer R extends string ? R : never;