String length in the type

Viewed 495

I have a a need to create a type that is a single character.

type Symbol = string

However I am not able to do this. The closest I got was doing:

const CHARS = { a: 1, b: 1, c: 1 /*, and so on */ } 
type Symbol = $Keys<typeof CHARS>;

CHARS is an object where keys are every single character on the keyboard, then I make an enum out of it. This is not good though, because it doesn't accommodate all chars, like on foreign keyboards.

1 Answers
Related